[opt](memory) All LRU Cache inherit from LRUCachePolicy (#28940)

After all LRU Cache inherits from LRUCachePolicy, this will allow prune stale entry, eviction when memory exceeds limit, and define common properties. LRUCache constructor change to private, only allow LRUCachePolicy to construct it.

Impl DummyLRUCache, when LRU Cache capacity is 0, will no longer be meaningless insert and evict.
This commit is contained in:
Xinyi Zou
2023-12-29 16:15:56 +08:00
committed by GitHub
parent 866fd5d32a
commit 82635d4b59
30 changed files with 367 additions and 207 deletions

View File

@ -27,6 +27,9 @@ int64_t CacheManager::for_each_cache_prune_stale_wrap(
int64_t freed_size = 0;
std::lock_guard<std::mutex> l(_caches_lock);
for (auto cache_policy : _caches) {
if (!cache_policy->enable_prune()) {
continue;
}
func(cache_policy);
freed_size += cache_policy->profile()->get_counter("FreedMemory")->value();
if (cache_policy->profile()->get_counter("FreedMemory")->value() != 0 && profile) {