1 #ifndef ACOMMON_CACHE_T__HPP
2 #define ACOMMON_CACHE_T__HPP
7 //#include "iostream.hpp"
15 public: // but don't use
17 GlobalCacheBase * next;
18 GlobalCacheBase * * prev;
21 void del(Cacheable * d);
22 void add(Cacheable * n);
23 GlobalCacheBase(const char * n);
26 void release(Cacheable * d);
27 void detach(Cacheable * d);
32 class GlobalCache : public GlobalCacheBase
36 typedef typename Data::CacheKey Key;
38 GlobalCache(const char * n) : GlobalCacheBase(n) {}
39 // "find" and "add" will _not_ acquire a lock
40 Data * find(const Key & key) {
41 D * cur = static_cast<D *>(first);
42 while (cur && !cur->cache_key_eq(key))
43 cur = static_cast<D *>(cur->next);
46 void add(Data * n) {GlobalCacheBase::add(n);}
47 // "release" and "detach" _will_ acquire a lock
48 void release(Data * d) {GlobalCacheBase::release(d);}
49 void detach(Data * d) {GlobalCacheBase::detach(d);}
53 PosibErr<Data *> get_cache_data(GlobalCache<Data> * cache,
54 typename Data::CacheConfig * config,
55 const typename Data::CacheKey & key)
58 Data * n = cache->find(key);
59 //CERR << "Getting " << key << " for " << cache->name << "\n";
64 PosibErr<Data *> res = Data::get_new(key, config);
71 //CERR << "LOADED FROM DISK\n";
76 PosibErr<Data *> get_cache_data(GlobalCache<Data> * cache,
77 typename Data::CacheConfig * config,
78 typename Data::CacheConfig2 * config2,
79 const typename Data::CacheKey & key)
82 Data * n = cache->find(key);
83 //CERR << "Getting " << key << "\n";
88 PosibErr<Data *> res = Data::get_new(key, config, config2);
95 //CERR << "LOADED FROM DISK\n";