Page Speed Optimization Libraries  1.4.26.1
net/instaweb/system/public/system_caches.h
Go to the documentation of this file.
00001 // Copyright 2013 Google Inc.
00017 
00018 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
00019 #define NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
00020 
00021 #include <map>
00022 #include <vector>
00023 
00024 #include "net/instaweb/util/public/basictypes.h"
00025 #include "net/instaweb/util/public/cache_interface.h"
00026 #include "net/instaweb/util/public/md5_hasher.h"
00027 #include "net/instaweb/util/public/scoped_ptr.h"
00028 #include "net/instaweb/util/public/shared_mem_cache.h"
00029 #include "net/instaweb/util/public/string.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class AbstractSharedMem;
00034 class AprMemCache;
00035 class AsyncCache;
00036 class MessageHandler;
00037 class NamedLockManager;
00038 class QueuedWorkerPool;
00039 class RewriteDriverFactory;
00040 class ServerContext;
00041 class SlowWorker;
00042 class Statistics;
00043 class SystemCachePath;
00044 class SystemRewriteOptions;
00045 
00059 class SystemCaches {
00060  public:
00062   static const char kMemcached[];
00063   static const char kShmCache[];
00064 
00065   enum StatFlags {
00066     kDefaultStatFlags = 0,
00067     kGlobalView = 1,
00068     kIncludeMemcached = 2
00069   };
00070 
00072   static void InitStats(Statistics* statistics);
00073 
00076   SystemCaches(RewriteDriverFactory* factory,
00077                AbstractSharedMem* shm_runtime,
00078                int thread_limit);
00079 
00081   ~SystemCaches();
00082 
00083   bool is_root_process() const { return is_root_process_; }
00084 
00087   void RegisterConfig(SystemRewriteOptions* config);
00088   void RootInit();
00089   void ChildInit();
00090 
00094   void StopCacheActivity();
00095 
00098   void ShutDown(MessageHandler* message_handler);
00099 
00101   void SetupCaches(ServerContext* server_context);
00102 
00108   bool CreateShmMetadataCache(const GoogleString& name, int64 size_kb,
00109                               GoogleString* error_msg);
00110 
00113   NamedLockManager* GetLockManager(SystemRewriteOptions* config);
00114 
00116   void PrintCacheStats(StatFlags flags, GoogleString* out);
00117 
00118  private:
00119   typedef SharedMemCache<64> MetadataShmCache;
00120   struct MetadataShmCacheInfo {
00121     MetadataShmCacheInfo() : cache_backend(NULL) {}
00122 
00124     scoped_ptr<CacheInterface> cache_to_use; 
00125     MetadataShmCache* cache_backend;
00126   };
00127 
00129   AprMemCache* NewAprMemCache(const GoogleString& spec);
00130 
00135   SystemCachePath* GetCache(SystemRewriteOptions* config);
00136 
00142   CacheInterface* GetMemcached(SystemRewriteOptions* config);
00143 
00146   CacheInterface* GetFilesystemMetadataCache(SystemRewriteOptions* config);
00147 
00150   CacheInterface* GetShmMetadataCache(SystemRewriteOptions* config);
00151 
00152   scoped_ptr<SlowWorker> slow_worker_;
00153 
00154   RewriteDriverFactory* factory_;
00155   AbstractSharedMem* shared_mem_runtime_;
00156   int thread_limit_;
00157   bool is_root_process_;
00158   bool was_shut_down_;
00159 
00169   typedef std::map<GoogleString, SystemCachePath*> PathCacheMap;
00170   PathCacheMap path_cache_map_;
00171 
00187   typedef std::map<GoogleString, CacheInterface*> MemcachedMap;
00188   MemcachedMap memcached_map_;
00189   scoped_ptr<QueuedWorkerPool> memcached_pool_;
00190   std::vector<AprMemCache*> memcache_servers_;
00191   std::vector<AsyncCache*> async_caches_;
00192 
00195   typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap;
00196 
00198   MetadataShmCacheMap metadata_shm_caches_;
00199 
00200   MD5Hasher cache_hasher_;
00201 
00202   DISALLOW_COPY_AND_ASSIGN(SystemCaches);
00203 };
00204 
00205 }  
00206 
00207 #endif  ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
00208 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines