35 #include <InternalErr.h> 37 #include "ObjMemCache.h" 44 ObjMemCache::~ObjMemCache()
46 for (cache_t::iterator i = cache.begin(), e = cache.end(); i != e; ++i) {
68 if (d_entries_threshold && (d_count > d_entries_threshold))
69 purge(d_purge_threshold);
71 index.insert(index_pair_t(key, d_count));
73 cache.insert(cache_pair_t(d_count,
new Entry(obj, key)));
82 index_t::iterator i = index.find(key);
84 if (i != index.end()) {
85 unsigned int count = i->second;
87 cache_t::iterator c = cache.find(count);
88 assert(c != cache.end());
102 DapObj *cached_obj = 0;
104 index_t::iterator i = index.find(key);
105 if (i != index.end()) {
106 cache_t::iterator c = cache.find(i->second);
107 assert(c != cache.end());
110 if (c != cache.end()) {
113 Entry *e = c->second;
114 cached_obj = e->d_obj;
118 cache.insert(cache_pair_t(++d_count, e));
125 throw InternalErr(__FILE__, __LINE__,
"Memory cache consistency error.");
130 index.insert(index_pair_t(key, d_count));
143 size_t num_remove = cache.size() * fraction;
145 cache_t::iterator c = cache.begin(), e = cache.end();
146 for (
unsigned int i = 0; i < num_remove && c != e; ++i) {
147 const string name = c->second->d_name;
152 index_t::iterator pos = index.find(name);
153 assert(pos != index.end());
virtual libdap::DapObj * get(const std::string &key)
Get the cached pointer.
virtual void purge(float fraction)
Purge the oldest elements.
virtual void add(libdap::DapObj *obj, const std::string &key)
Added a DDS to the cache and associate it with a key Add the pointer to the cache, purging the cache of the least recently used items if the cache was initialized with a specific threshold value. If not, the caller must take care of calling the purge() method.
virtual void remove(const std::string &key)
Remove the object associated with a key.