Commit 74570104 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Cache: Allow deletion by cache key

parent 89ee7fbe
......@@ -102,11 +102,9 @@ class Cache
return res;
}
static bool destroy( sqlite3* dbConnection, const std::shared_ptr<IMPL>& self )
static bool destroy( sqlite3* dbConnection, const typename CACHEPOLICY::KeyType& key )
{
std::lock_guard<std::mutex> lock( Mutex );
auto key = CACHEPOLICY::key( self );
auto it = Store.find( key );
if ( it != Store.end() )
Store.erase( it );
......@@ -115,6 +113,12 @@ class Cache
return SqliteTools::executeDelete( dbConnection, req.c_str(), key );
}
static bool destroy( sqlite3* dbConnection, const std::shared_ptr<IMPL>& self )
{
const auto& key = CACHEPOLICY::key( self );
return destroy( dbConnection, key );
}
private:
static std::unordered_map<typename CACHEPOLICY::KeyType, std::shared_ptr<IMPL> > Store;
static std::mutex Mutex;
......
......@@ -60,8 +60,7 @@ LabelPtr MediaLibrary::createLabel( const std::string& label )
bool MediaLibrary::deleteLabel( const std::string& text )
{
auto label = Label::fetch( m_dbConnection, text );
return deleteLabel( label );
return Label::destroy( m_dbConnection, text );
}
bool MediaLibrary::deleteLabel( LabelPtr label )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment