00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_WRITE_THROUGH_CACHE_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_WRITE_THROUGH_CACHE_H_
00021
00022 #include <cstddef>
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/cache_interface.h"
00025 #include "net/instaweb/util/public/string.h"
00026
00027 namespace net_instaweb {
00028
00029 class SharedString;
00030
00032 class WriteThroughCache : public CacheInterface {
00033 public:
00034 static const size_t kUnlimited;
00035
00037 WriteThroughCache(CacheInterface* cache1, CacheInterface* cache2)
00038 : cache1_(cache1),
00039 cache2_(cache2),
00040 cache1_size_limit_(kUnlimited),
00041 name_(StrCat("WriteThroughCache using backend 1 : ", cache1->Name(),
00042 " and backend 2 : ", cache2->Name())) {}
00043
00044 virtual ~WriteThroughCache();
00045
00046 virtual void Get(const GoogleString& key, Callback* callback);
00047 virtual void Put(const GoogleString& key, SharedString* value);
00048 virtual void Delete(const GoogleString& key);
00049
00054 void set_cache1_limit(size_t limit) { cache1_size_limit_ = limit; }
00055
00056 CacheInterface* cache1() { return cache1_; }
00057 CacheInterface* cache2() { return cache2_; }
00058 virtual const char* Name() const { return name_.c_str(); }
00059
00060 private:
00061 void PutInCache1(const GoogleString& key, SharedString* value);
00062 friend class WriteThroughCallback;
00063
00064 CacheInterface* cache1_;
00065 CacheInterface* cache2_;
00066 size_t cache1_size_limit_;
00067 GoogleString name_;
00068
00069 DISALLOW_COPY_AND_ASSIGN(WriteThroughCache);
00070 };
00071
00072 }
00073
00074 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_WRITE_THROUGH_CACHE_H_