Page Speed Optimization Libraries  1.8.31.3
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/md5_hasher.h"
00026 #include "net/instaweb/util/public/scoped_ptr.h"
00027 #include "net/instaweb/util/public/shared_mem_cache.h"
00028 #include "net/instaweb/util/public/string.h"
00029 
00030 namespace net_instaweb {
00031 
00032 class AbstractSharedMem;
00033 class AprMemCache;
00034 class CacheInterface;
00035 class MessageHandler;
00036 class NamedLockManager;
00037 class QueuedWorkerPool;
00038 class RewriteDriverFactory;
00039 class ServerContext;
00040 class SlowWorker;
00041 class Statistics;
00042 class SystemCachePath;
00043 class SystemRewriteOptions;
00044 
00058 class SystemCaches {
00059  public:
00061   static const char kMemcachedAsync[];
00062   static const char kMemcachedBlocking[];
00063   static const char kShmCache[];
00064 
00065   static const char kDefaultSharedMemoryPath[];
00066 
00067   enum StatFlags {
00068     kDefaultStatFlags = 0,
00069     kGlobalView = 1,
00070     kIncludeMemcached = 2
00071   };
00072 
00074   static void InitStats(Statistics* statistics);
00075 
00078   SystemCaches(RewriteDriverFactory* factory,
00079                AbstractSharedMem* shm_runtime,
00080                int thread_limit);
00081 
00083   ~SystemCaches();
00084 
00085   bool is_root_process() const { return is_root_process_; }
00086 
00089   void RegisterConfig(SystemRewriteOptions* config);
00090   void RootInit();
00091   void ChildInit();
00092 
00096   void StopCacheActivity();
00097 
00100   void ShutDown(MessageHandler* message_handler);
00101 
00103   void SetupCaches(ServerContext* server_context, bool enable_property_cache);
00104 
00110   bool CreateShmMetadataCache(const GoogleString& name, int64 size_kb,
00111                               GoogleString* error_msg);
00112 
00115   NamedLockManager* GetLockManager(SystemRewriteOptions* config);
00116 
00118   void PrintCacheStats(StatFlags flags, GoogleString* out);
00119 
00122   void set_thread_limit(int thread_limit) { thread_limit_ = thread_limit; }
00123 
00135   SystemCachePath* GetCache(SystemRewriteOptions* config);
00136 
00137  private:
00138   typedef SharedMemCache<64> MetadataShmCache;
00139   struct MetadataShmCacheInfo {
00140     MetadataShmCacheInfo()
00141         : cache_to_use(NULL), cache_backend(NULL), initialized(false) {}
00142 
00144     CacheInterface* cache_to_use; 
00145     GoogleString segment;
00146     MetadataShmCache* cache_backend;
00147     bool initialized; 
00148 
00149 
00150   };
00151 
00152   struct MemcachedInterfaces {
00153     MemcachedInterfaces() : async(NULL), blocking(NULL) {}
00154     CacheInterface* async;
00155     CacheInterface* blocking;
00156   };
00157 
00159   AprMemCache* NewAprMemCache(const GoogleString& spec);
00160 
00170   MemcachedInterfaces GetMemcached(SystemRewriteOptions* config);
00171 
00174   MetadataShmCacheInfo* LookupShmMetadataCache(const GoogleString& name);
00175 
00180   MetadataShmCacheInfo* GetShmMetadataCacheOrDefault(
00181       SystemRewriteOptions* config);
00182 
00184   void SetupPcacheCohorts(ServerContext* server_context,
00185                           bool enable_property_cache);
00186 
00187   scoped_ptr<SlowWorker> slow_worker_;
00188 
00189   RewriteDriverFactory* factory_;
00190   AbstractSharedMem* shared_mem_runtime_;
00191   int thread_limit_;
00192   bool is_root_process_;
00193   bool was_shut_down_;
00194 
00204   typedef std::map<GoogleString, SystemCachePath*> PathCacheMap;
00205   PathCacheMap path_cache_map_;
00206 
00222   typedef std::map<GoogleString, MemcachedInterfaces> MemcachedMap;
00223   MemcachedMap memcached_map_;
00224   scoped_ptr<QueuedWorkerPool> memcached_pool_;
00225   std::vector<AprMemCache*> memcache_servers_;
00226 
00229   typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap;
00230 
00232   MetadataShmCacheMap metadata_shm_caches_;
00233 
00234   MD5Hasher cache_hasher_;
00235 
00236   bool default_shm_metadata_cache_creation_failed_;
00237 
00238   DISALLOW_COPY_AND_ASSIGN(SystemCaches);
00239 };
00240 
00241 }  
00242 
00243 #endif  ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines