29 #ifndef DAP_OBJMEMCACHE_H_ 30 #define DAP_OBJMEMCACHE_H_ 75 libdap::DapObj *d_obj;
76 const std::string d_name;
79 Entry(libdap::DapObj *o,
const std::string &n): d_obj(o), d_name(n) { }
81 ~Entry() {
delete d_obj; d_obj = 0;}
85 unsigned int d_entries_threshold;
86 float d_purge_threshold;
88 typedef std::pair<unsigned int, Entry*> cache_pair_t;
89 typedef std::map<unsigned int, Entry*> cache_t;
92 typedef std::pair<const std::string, unsigned int> index_pair_t;
94 typedef std::map<const std::string, unsigned int> index_t;
97 friend class DDSMemCacheTest;
108 ObjMemCache(): d_count(0), d_entries_threshold(0), d_purge_threshold(0.2) { }
119 ObjMemCache(
unsigned int entries_threshold,
float purge_threshold): d_count(0),
120 d_entries_threshold(entries_threshold), d_purge_threshold(purge_threshold) { }
124 virtual void add(libdap::DapObj *obj,
const std::string &key);
126 virtual void remove(
const std::string &key);
128 virtual libdap::DapObj *
get(
const std::string &key);
134 virtual unsigned int size()
const {
135 assert(cache.size() == index.size());
139 virtual void purge(
float fraction);
145 virtual void dump(ostream &os) {
146 os <<
"ObjMemCache" << endl;
147 os <<
"Length of index: " << index.size() << endl;
148 for(index_t::const_iterator it = index.begin(); it != index.end(); ++it) {
149 os << it->first <<
" --> " << it->second << endl;
152 os <<
"Length of cache: " << cache.size() << endl;
153 for(cache_t::const_iterator it = cache.begin(); it != cache.end(); ++it) {
154 os << it->first <<
" --> " << it->second->d_name << endl;
ObjMemCache()
Initialize the DapObj cache This constructor builds a cache that will require the caller manage the p...
virtual unsigned int size() const
How many items are in the cache.
virtual void dump(ostream &os)
What is in the cache.
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.
ObjMemCache(unsigned int entries_threshold, float purge_threshold)
Initialize the DapObj cache to use an item count threshold The purge() method will be automatically r...
An in-memory cache for DapObj (DAS, DDS, ...) objects.