Page Speed Optimization Libraries
1.7.30.4
|
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 00124 private: 00125 typedef SharedMemCache<64> MetadataShmCache; 00126 struct MetadataShmCacheInfo { 00127 MetadataShmCacheInfo() 00128 : cache_to_use(NULL), cache_backend(NULL), initialized(false) {} 00129 00131 CacheInterface* cache_to_use; 00132 GoogleString segment; 00133 MetadataShmCache* cache_backend; 00134 bool initialized; 00135 00136 00137 }; 00138 00139 struct MemcachedInterfaces { 00140 MemcachedInterfaces() : async(NULL), blocking(NULL) {} 00141 CacheInterface* async; 00142 CacheInterface* blocking; 00143 }; 00144 00146 AprMemCache* NewAprMemCache(const GoogleString& spec); 00147 00152 SystemCachePath* GetCache(SystemRewriteOptions* config); 00153 00163 MemcachedInterfaces GetMemcached(SystemRewriteOptions* config); 00164 00167 CacheInterface* LookupShmMetadataCache(const GoogleString& name); 00168 00173 CacheInterface* GetShmMetadataCacheOrDefault(SystemRewriteOptions* config); 00174 00176 void SetupPcacheCohorts(ServerContext* server_context, 00177 bool enable_property_cache); 00178 00179 scoped_ptr<SlowWorker> slow_worker_; 00180 00181 RewriteDriverFactory* factory_; 00182 AbstractSharedMem* shared_mem_runtime_; 00183 int thread_limit_; 00184 bool is_root_process_; 00185 bool was_shut_down_; 00186 00196 typedef std::map<GoogleString, SystemCachePath*> PathCacheMap; 00197 PathCacheMap path_cache_map_; 00198 00214 typedef std::map<GoogleString, MemcachedInterfaces> MemcachedMap; 00215 MemcachedMap memcached_map_; 00216 scoped_ptr<QueuedWorkerPool> memcached_pool_; 00217 std::vector<AprMemCache*> memcache_servers_; 00218 00221 typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap; 00222 00224 MetadataShmCacheMap metadata_shm_caches_; 00225 00226 MD5Hasher cache_hasher_; 00227 00228 bool default_shm_metadata_cache_creation_failed_; 00229 00230 DISALLOW_COPY_AND_ASSIGN(SystemCaches); 00231 }; 00232 00233 } 00234 00235 #endif ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_