29 #ifndef DAP_OBJMEMCACHE_H_
30 #define DAP_OBJMEMCACHE_H_
37 #include "BESIndent.h"
87 libdap::DapObj *d_obj;
88 const std::string d_name;
91 Entry(libdap::DapObj *o,
const std::string &n): d_obj(o), d_name(n) { }
93 ~Entry() {
delete d_obj; d_obj = 0;}
96 unsigned long long d_age;
97 unsigned int d_entries_threshold;
98 float d_purge_threshold;
100 typedef std::pair<unsigned int, Entry*> cache_pair_t;
101 typedef std::map<unsigned int, Entry*> cache_t;
104 typedef std::pair<const std::string, unsigned int> index_pair_t;
106 typedef std::map<const std::string, unsigned int> index_t;
109 friend class DDSMemCacheTest;
120 ObjMemCache(): d_age(0), d_entries_threshold(0), d_purge_threshold(0.2) { }
132 ObjMemCache(
unsigned int entries_threshold,
float purge_threshold): d_age(0),
133 d_entries_threshold(entries_threshold), d_purge_threshold(purge_threshold) {
139 virtual void add(libdap::DapObj *obj,
const std::string &key);
141 virtual void remove(
const std::string &key);
143 virtual libdap::DapObj *
get(
const std::string &key);
149 virtual unsigned int size()
const {
150 assert(cache.size() == index.size());
154 virtual void purge(
float fraction);
160 virtual void dump(ostream &os) {
161 os <<
"ObjMemCache" << std::endl;
162 os <<
"Length of index: " << index.size() << std::endl;
163 for(index_t::const_iterator it = index.begin(); it != index.end(); ++it) {
164 os << it->first <<
" --> " << it->second << std::endl;
167 os <<
"Length of cache: " << cache.size() << std::endl;
168 for(cache_t::const_iterator it = cache.begin(); it != cache.end(); ++it) {
169 os << it->first <<
" --> " << it->second->d_name << std::endl;