Page Speed Optimization Libraries  1.5.27.2
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   enum StatFlags {
00065     kDefaultStatFlags = 0,
00066     kGlobalView = 1,
00067     kIncludeMemcached = 2
00068   };
00069 
00071   static void InitStats(Statistics* statistics);
00072 
00075   SystemCaches(RewriteDriverFactory* factory,
00076                AbstractSharedMem* shm_runtime,
00077                int thread_limit);
00078 
00080   ~SystemCaches();
00081 
00082   bool is_root_process() const { return is_root_process_; }
00083 
00086   void RegisterConfig(SystemRewriteOptions* config);
00087   void RootInit();
00088   void ChildInit();
00089 
00093   void StopCacheActivity();
00094 
00097   void ShutDown(MessageHandler* message_handler);
00098 
00100   void SetupCaches(ServerContext* server_context);
00101 
00107   bool CreateShmMetadataCache(const GoogleString& name, int64 size_kb,
00108                               GoogleString* error_msg);
00109 
00112   NamedLockManager* GetLockManager(SystemRewriteOptions* config);
00113 
00115   void PrintCacheStats(StatFlags flags, GoogleString* out);
00116 
00117  private:
00118   typedef SharedMemCache<64> MetadataShmCache;
00119   struct MetadataShmCacheInfo {
00120     MetadataShmCacheInfo() : cache_backend(NULL) {}
00121 
00123     CacheInterface* cache_to_use; 
00124     MetadataShmCache* cache_backend;
00125   };
00126 
00128   AprMemCache* NewAprMemCache(const GoogleString& spec);
00129 
00134   SystemCachePath* GetCache(SystemRewriteOptions* config);
00135 
00141   CacheInterface* GetMemcached(SystemRewriteOptions* config);
00142 
00145   CacheInterface* GetFilesystemMetadataCache(SystemRewriteOptions* config);
00146 
00149   CacheInterface* GetShmMetadataCache(SystemRewriteOptions* config);
00150 
00151   scoped_ptr<SlowWorker> slow_worker_;
00152 
00153   RewriteDriverFactory* factory_;
00154   AbstractSharedMem* shared_mem_runtime_;
00155   int thread_limit_;
00156   bool is_root_process_;
00157   bool was_shut_down_;
00158 
00168   typedef std::map<GoogleString, SystemCachePath*> PathCacheMap;
00169   PathCacheMap path_cache_map_;
00170 
00186   typedef std::map<GoogleString, CacheInterface*> MemcachedMap;
00187   MemcachedMap memcached_map_;
00188   scoped_ptr<QueuedWorkerPool> memcached_pool_;
00189   std::vector<AprMemCache*> memcache_servers_;
00190 
00193   typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap;
00194 
00196   MetadataShmCacheMap metadata_shm_caches_;
00197 
00198   MD5Hasher cache_hasher_;
00199 
00200   DISALLOW_COPY_AND_ASSIGN(SystemCaches);
00201 };
00202 
00203 }  
00204 
00205 #endif  ///< NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines