2011-09-11 11:10:31 +04:00
|
|
|
#ifndef POLYSETCACHE_H_
|
|
|
|
#define POLYSETCACHE_H_
|
|
|
|
|
2011-11-09 06:18:32 +04:00
|
|
|
#include "cache.h"
|
2011-09-11 11:10:31 +04:00
|
|
|
#include "memory.h"
|
|
|
|
|
|
|
|
class PolySetCache
|
|
|
|
{
|
|
|
|
public:
|
2012-01-06 22:10:33 +04:00
|
|
|
PolySetCache(size_t memorylimit = 100*1024*1024) : cache(memorylimit) {}
|
2011-09-11 11:10:31 +04:00
|
|
|
|
|
|
|
static PolySetCache *instance() { if (!inst) inst = new PolySetCache; return inst; }
|
|
|
|
|
|
|
|
bool contains(const std::string &id) const { return this->cache.contains(id); }
|
|
|
|
shared_ptr<class PolySet> get(const std::string &id) const { return this->cache[id]->ps; }
|
|
|
|
void insert(const std::string &id, const shared_ptr<PolySet> &ps);
|
2012-01-06 22:10:33 +04:00
|
|
|
size_t maxSize() const;
|
|
|
|
void setMaxSize(size_t limit);
|
2011-09-11 11:10:31 +04:00
|
|
|
void clear() { cache.clear(); }
|
|
|
|
void print();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static PolySetCache *inst;
|
|
|
|
|
|
|
|
struct cache_entry {
|
|
|
|
shared_ptr<class PolySet> ps;
|
2011-11-01 02:56:35 +04:00
|
|
|
std::string msg;
|
2011-09-11 11:10:31 +04:00
|
|
|
cache_entry(const shared_ptr<PolySet> &ps);
|
|
|
|
~cache_entry() { }
|
|
|
|
};
|
|
|
|
|
2011-11-09 06:18:32 +04:00
|
|
|
Cache<std::string, cache_entry> cache;
|
2011-09-11 11:10:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|