@ -147,6 +147,7 @@ class LRUCache {
Cache : : Handle * Lookup ( const Slice & key , uint32_t hash ) ;
Cache : : Handle * Lookup ( const Slice & key , uint32_t hash ) ;
void Release ( Cache : : Handle * handle ) ;
void Release ( Cache : : Handle * handle ) ;
void Erase ( const Slice & key , uint32_t hash ) ;
void Erase ( const Slice & key , uint32_t hash ) ;
void Prune ( ) ;
private :
private :
void LRU_Remove ( LRUHandle * e ) ;
void LRU_Remove ( LRUHandle * e ) ;
@ -264,6 +265,19 @@ void LRUCache::Erase(const Slice& key, uint32_t hash) {
}
}
}
}
void LRUCache : : Prune ( ) {
MutexLock l ( & mutex_ ) ;
for ( LRUHandle * e = lru_ . next ; e ! = & lru_ ; ) {
LRUHandle * next = e - > next ;
if ( e - > refs = = 1 ) {
table_ . Remove ( e - > key ( ) , e - > hash ) ;
LRU_Remove ( e ) ;
Unref ( e ) ;
}
e = next ;
}
}
static const int kNumShardBits = 4 ;
static const int kNumShardBits = 4 ;
static const int kNumShards = 1 < < kNumShardBits ;
static const int kNumShards = 1 < < kNumShardBits ;
@ -314,6 +328,11 @@ class ShardedLRUCache : public Cache {
MutexLock l ( & id_mutex_ ) ;
MutexLock l ( & id_mutex_ ) ;
return + + ( last_id_ ) ;
return + + ( last_id_ ) ;
}
}
virtual void Prune ( ) {
for ( int s = 0 ; s < kNumShards ; s + + ) {
shard_ [ s ] . Prune ( ) ;
}
}
} ;
} ;
} // end anonymous namespace
} // end anonymous namespace