29 #ifndef DAP_OBJMEMCACHE_H_ 30 #define DAP_OBJMEMCACHE_H_ 37 #include "BESIndent.h" 89 libdap::DapObj *d_obj;
90 const std::string d_name;
93 Entry(libdap::DapObj *o,
const std::string &n): d_obj(o), d_name(n) { }
95 ~Entry() {
delete d_obj; d_obj = 0;}
98 unsigned long long d_age;
99 unsigned int d_entries_threshold;
100 float d_purge_threshold;
102 typedef std::pair<unsigned int, Entry*> cache_pair_t;
103 typedef std::map<unsigned int, Entry*> cache_t;
106 typedef std::pair<const std::string, unsigned int> index_pair_t;
108 typedef std::map<const std::string, unsigned int> index_t;
111 friend class DDSMemCacheTest;
122 ObjMemCache(): d_age(0), d_entries_threshold(0), d_purge_threshold(0.2) { }
134 ObjMemCache(
unsigned int entries_threshold,
float purge_threshold): d_age(0),
135 d_entries_threshold(entries_threshold), d_purge_threshold(purge_threshold) {
141 virtual void add(libdap::DapObj *obj,
const std::string &key);
143 virtual void remove(
const std::string &key);
145 virtual libdap::DapObj *get(
const std::string &key);
151 virtual unsigned int size()
const {
152 assert(cache.size() == index.size());
156 virtual void purge(
float fraction);
162 virtual void dump(ostream &os) {
163 os <<
"ObjMemCache" << endl;
164 os <<
"Length of index: " << index.size() << endl;
165 for(index_t::const_iterator it = index.begin(); it != index.end(); ++it) {
166 os << it->first <<
" --> " << it->second << endl;
169 os <<
"Length of cache: " << cache.size() << endl;
170 for(cache_t::const_iterator it = cache.begin(); it != cache.end(); ++it) {
171 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.
ObjMemCache(unsigned int entries_threshold, float purge_threshold)
Initialize the DapObj cache to use an item count threshold.
An in-memory cache for DapObj (DAS, DDS, ...) objects.