summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
Diffstat (limited to 'cache.h')
-rwxr-xr-xcache.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/cache.h b/cache.h
index 0b81cf5..4b78ee5 100755
--- a/cache.h
+++ b/cache.h
@@ -68,16 +68,25 @@ public:
m_currentWeight -= result->weight();
m_values.erase( it->second );
- m_lookup.erase( it );
+ //m_lookup.erase( it );
}
- if ( !result->load() )
+ if ( !result->load() ) {
+ if ( it != m_lookup.end() )
+ m_lookup.erase( it );
return ptr_type();
+ }
// put new object into cache
if ( result->weight() < m_maxWeight ) {
m_currentWeight += result->weight();
- m_lookup.insert( std::make_pair( key, m_values.insert( m_values.begin(), std::make_pair( key, result ) ) ) );
+
+ typename ValueList::iterator element = m_values.insert( m_values.begin(), std::make_pair( key, result ) );
+ if ( it != m_lookup.end() )
+ it->second = element;
+ else
+ m_lookup.insert( std::make_pair( key, element ) );
+
while ( m_currentWeight > m_maxWeight ) {
value_type& value = m_values.back();
m_currentWeight -= value.second->weight();