summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rgw/rgw_cache.cc5
-rw-r--r--src/rgw/rgw_cache.h3
2 files changed, 6 insertions, 2 deletions
diff --git a/src/rgw/rgw_cache.cc b/src/rgw/rgw_cache.cc
index 5b96eb45b08..d0afdcd389c 100644
--- a/src/rgw/rgw_cache.cc
+++ b/src/rgw/rgw_cache.cc
@@ -107,7 +107,7 @@ void ObjectCache::remove(string& name)
void ObjectCache::touch_lru(string& name, std::list<string>::iterator& lru_iter)
{
- while (lru.size() > (size_t)cct->_conf->rgw_cache_lru_size) {
+ while (lru_size > (size_t)cct->_conf->rgw_cache_lru_size) {
list<string>::iterator iter = lru.begin();
if ((*iter).compare(name) == 0) {
/*
@@ -121,10 +121,12 @@ void ObjectCache::touch_lru(string& name, std::list<string>::iterator& lru_iter)
if (map_iter != cache_map.end())
cache_map.erase(map_iter);
lru.pop_front();
+ lru_size--;
}
if (lru_iter == lru.end()) {
lru.push_back(name);
+ lru_size++;
lru_iter--;
ldout(cct, 10) << "adding " << name << " to cache LRU end" << dendl;
} else {
@@ -142,6 +144,7 @@ void ObjectCache::remove_lru(string& name, std::list<string>::iterator& lru_iter
return;
lru.erase(lru_iter);
+ lru_size--;
lru_iter = lru.end();
}
diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h
index 601fcdfc963..3f17883f215 100644
--- a/src/rgw/rgw_cache.h
+++ b/src/rgw/rgw_cache.h
@@ -131,13 +131,14 @@ struct ObjectCacheEntry {
class ObjectCache {
std::map<string, ObjectCacheEntry> cache_map;
std::list<string> lru;
+ uint32_t lru_size;
Mutex lock;
CephContext *cct;
void touch_lru(string& name, std::list<string>::iterator& lru_iter);
void remove_lru(string& name, std::list<string>::iterator& lru_iter);
public:
- ObjectCache() : lock("ObjectCache"), cct(NULL) { }
+ ObjectCache() : lru_size(0), lock("ObjectCache"), cct(NULL) { }
int get(std::string& name, ObjectCacheInfo& bl, uint32_t mask);
void put(std::string& name, ObjectCacheInfo& bl);
void remove(std::string& name);