Page Speed Optimization Libraries  1.7.30.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 kMemcached[];
00062   static const char kShmCache[];
00063 
00064   static const char kDefaultSharedMemoryPath[];
00065 
00066   enum StatFlags {
00067     kDefaultStatFlags = 0,
00068     kGlobalView = 1,
00069     kIncludeMemcached = 2
00070   };
00071 
00073   static void InitStats(Statistics* statistics);
00074 
00077   SystemCaches(RewriteDriverFactory* factory,
00078                AbstractSharedMem* shm_runtime,
00079                int thread_limit);
00080 
00082   ~SystemCaches();
00083 
00084   bool is_root_process() const { return is_root_process_; }
00085 
00088   void RegisterConfig(SystemRewriteOptions* config);
00089   void RootInit();
00090   void ChildInit();
00091 
00095   void StopCacheActivity();
00096 
00099   void ShutDown(MessageHandler* message_handler);
00100 
00102   void SetupCaches(ServerContext* server_context);
00103 
00109   bool CreateShmMetadataCache(const GoogleString& name, int64 size_kb,
00110                               GoogleString* error_msg);
00111 
00114   NamedLockManager* GetLockManager(SystemRewriteOptions* config);
00115 
00117   void PrintCacheStats(StatFlags flags, GoogleString* out);
00118 
00121   void set_thread_limit(int thread_limit) { thread_limit_ = thread_limit; }
00122 
00123  private:
00124   typedef SharedMemCache<64> MetadataShmCache;
00125   struct MetadataShmCacheInfo {
00126     MetadataShmCacheInfo()
00127         : cache_to_use(NULL), cache_backend(NULL), initialized(false) {}
00128 
00130     CacheInterface* cache_to_use; 
00131     GoogleString segment;
00132     MetadataShmCache* cache_backend;
00133     bool initialized; 
00134 
00135 
00136   };
00137 
00139   AprMemCache* NewAprMemCache(const GoogleString& spec);
00140 
00145   SystemCachePath* GetCache(SystemRewriteOptions* config);
00146 
00152   CacheInterface* GetMemcached(SystemRewriteOptions* config);
00153 
00156   CacheInterface* GetFilesystemMetadataCache(SystemRewriteOptions* config);
00157 
00160   CacheInterface* LookupShmMetadataCache(const GoogleString& name);
00161 
00166   CacheInterface* GetShmMetadataCacheOrDefault(SystemRewriteOptions* config);
00167 
00168   scoped_ptr<SlowWorker> slow_worker_;
00169 
00170   RewriteDriverFactory* factory_;
00171   AbstractSharedMem* shared_mem_runtime_;
00172   int thread_limit_;
00173   bool is_root_process_;
00174   bool was_shut_down_;
00175 
00185   typedef std::map<GoogleString, SystemCachePath*> PathCacheMap;
00186   PathCacheMap path_cache_map_;
00187 
00203   typedef std::map<GoogleString, CacheInterface*> MemcachedMap;
00204   MemcachedMap memcached_map_;
00205   scoped_ptr<QueuedWorkerPool> memcached_pool_;
00206   std::vector<AprMemCache*> memcache_servers_;
00207 
00210   typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap;
00211 
00213   MetadataShmCacheMap metadata_shm_caches_;
00214 
00215   MD5Hasher cache_hasher_;
00216 
00217   bool default_shm_metadata_cache_creation_failed_;
00218 
00219   DISALLOW_COPY_AND_ASSIGN(SystemCaches);
00220 };
00221 
00222 }  
00223 
00224 #endif  ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines