Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
system_caches.h
Go to the documentation of this file.
1 // Copyright 2013 Google Inc.
17 
18 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
19 #define NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_CACHES_H_
20 
21 #include <map>
22 #include <vector>
23 
25 #include "net/instaweb/util/public/md5_hasher.h"
27 #include "net/instaweb/util/public/shared_mem_cache.h"
29 #include "pagespeed/kernel/base/string_util.h"
30 
31 namespace net_instaweb {
32 
33 class AbstractSharedMem;
34 class AprMemCache;
35 class CacheInterface;
36 class MessageHandler;
37 class NamedLockManager;
38 class QueuedWorkerPool;
39 class RewriteDriverFactory;
40 class ServerContext;
41 class SlowWorker;
42 class Statistics;
43 class SystemCachePath;
44 class SystemRewriteOptions;
45 
59 class SystemCaches {
60  public:
62  static const char kMemcachedAsync[];
63  static const char kMemcachedBlocking[];
64  static const char kShmCache[];
65 
66  static const char kDefaultSharedMemoryPath[];
67 
68  enum StatFlags {
69  kDefaultStatFlags = 0,
70  kGlobalView = 1,
71  kIncludeMemcached = 2
72  };
73 
75  static void InitStats(Statistics* statistics);
76 
80  AbstractSharedMem* shm_runtime,
81  int thread_limit);
82 
84  ~SystemCaches();
85 
86  bool is_root_process() const { return is_root_process_; }
87 
90  void RegisterConfig(SystemRewriteOptions* config);
91  void RootInit();
92  void ChildInit();
93 
97  void StopCacheActivity();
98 
101  void ShutDown(MessageHandler* message_handler);
102 
104  void SetupCaches(ServerContext* server_context, bool enable_property_cache);
105 
112  StringPiece name, int64 size_kb, GoogleString* error_msg);
113 
116  NamedLockManager* GetLockManager(SystemRewriteOptions* config);
117 
119  void PrintCacheStats(StatFlags flags, GoogleString* out);
120 
123  void set_thread_limit(int thread_limit) { thread_limit_ = thread_limit; }
124 
137 
138  private:
139  typedef SharedMemCache<64> MetadataShmCache;
140  struct MetadataShmCacheInfo {
141  MetadataShmCacheInfo()
142  : cache_to_use(NULL), cache_backend(NULL), initialized(false) {}
143 
145  CacheInterface* cache_to_use;
146  GoogleString segment;
147  MetadataShmCache* cache_backend;
148  bool initialized;
149  };
152 
153  struct MemcachedInterfaces {
154  MemcachedInterfaces() : async(NULL), blocking(NULL) {}
155  CacheInterface* async;
156  CacheInterface* blocking;
157  };
158 
160  AprMemCache* NewAprMemCache(const GoogleString& spec);
161 
171  MemcachedInterfaces GetMemcached(SystemRewriteOptions* config);
172 
175  MetadataShmCacheInfo* LookupShmMetadataCache(const GoogleString& name);
176 
181  MetadataShmCacheInfo* GetShmMetadataCacheOrDefault(
182  SystemRewriteOptions* config);
183 
185  void SetupPcacheCohorts(ServerContext* server_context,
186  bool enable_property_cache);
187 
188  scoped_ptr<SlowWorker> slow_worker_;
189 
190  RewriteDriverFactory* factory_;
191  AbstractSharedMem* shared_mem_runtime_;
192  int thread_limit_;
193  bool is_root_process_;
194  bool was_shut_down_;
195 
205  typedef std::map<GoogleString, SystemCachePath*> PathCacheMap;
206  PathCacheMap path_cache_map_;
207 
223  typedef std::map<GoogleString, MemcachedInterfaces> MemcachedMap;
224  MemcachedMap memcached_map_;
225  scoped_ptr<QueuedWorkerPool> memcached_pool_;
226  std::vector<AprMemCache*> memcache_servers_;
227 
230  typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap;
231 
233  MetadataShmCacheMap metadata_shm_caches_;
234 
235  MD5Hasher cache_hasher_;
236 
237  bool default_shm_metadata_cache_creation_failed_;
238 
239  DISALLOW_COPY_AND_ASSIGN(SystemCaches);
240 };
241 
242 }
243 
244 #endif
void ShutDown(MessageHandler *message_handler)
NamedLockManager * GetLockManager(SystemRewriteOptions *config)
static const char kMemcachedAsync[]
CacheStats prefixes.
Definition: system_caches.h:62
void SetupCaches(ServerContext *server_context, bool enable_property_cache)
Configures server_context's caches based on its configuration.
~SystemCaches()
Note that you must call ShutDown() before this is deleted.
void PrintCacheStats(StatFlags flags, GoogleString *out)
Print out stats appropriate for the given flags combination.
Definition: system_rewrite_options.h:31
void RegisterConfig(SystemRewriteOptions *config)
bool CreateShmMetadataCache(StringPiece name, int64 size_kb, GoogleString *error_msg)
SystemCaches(RewriteDriverFactory *factory, AbstractSharedMem *shm_runtime, int thread_limit)
SystemCachePath * GetCache(SystemRewriteOptions *config)
Definition: system_caches.h:59
static void InitStats(Statistics *statistics)
Registers all statistics the cache backends may use.
Definition: system_cache_path.h:49
void set_thread_limit(int thread_limit)
Definition: system_caches.h:123
Definition: rewrite_driver_factory.h:73