CppCMS
cache_interface.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 // See accompanying file COPYING.TXT file for licensing details.
6 //
8 #ifndef CPPCMS_CACHE_INTERFACE_H
9 #define CPPCMS_CACHE_INTERFACE_H
10 
11 #include <string>
12 #include <set>
13 
14 #include <cppcms/defs.h>
15 #include <cppcms/serialization_classes.h>
16 #include <booster/noncopyable.h>
17 #include <booster/intrusive_ptr.h>
18 #include <booster/hold_ptr.h>
19 #include <cppcms/cstdint.h>
20 
21 namespace cppcms {
22 
23  class service;
24 
25  namespace impl {
26  class base_cache;
27  }
28  namespace http {
29  class context;
30  };
31 
32  class cache_interface;
33 
73  class CPPCMS_API triggers_recorder : public booster::noncopyable {
74  public:
87  std::set<std::string> detach();
88  private:
89  friend class cache_interface;
90  void add(std::string const &t);
91  struct data;
93  std::set<std::string> triggers_;
94  cache_interface *cache_;
95  };
96 
136 
137 
138 
139  class CPPCMS_API cache_interface : public booster::noncopyable {
140  public:
141 
154  cache_interface(http::context &context);
155  ~cache_interface();
156 
158 
162  void rise(std::string const &trigger);
163 
167 
168  void add_trigger(std::string const &trigger);
169 
173  void clear();
174 
178  void reset();
179 
188  bool stats(unsigned &keys,unsigned &triggers);
189 
193  bool has_cache();
194 
198  bool nocache();
199 
204  bool fetch_page(std::string const &key);
205 
216 
217  void store_page(std::string const &key,int timeout=-1);
218 
229  bool fetch_frame(std::string const &key,std::string &result,bool notriggers=false);
230 
242  void store_frame(std::string const &key,
243  std::string const &frame,
244  std::set<std::string> const &triggers=std::set<std::string>(),
245  int timeout=-1,
246  bool notriggers=false);
247 
257  void store_frame(std::string const &key,
258  std::string const &frame,
259  int timeout,
260  bool notriggers=false);
261 
272  template<typename Serializable>
273  bool fetch_data(std::string const &key,Serializable &data,bool notriggers=false)
274  {
275  std::string buffer;
276  if(!fetch(key,buffer,notriggers))
277  return false;
279  return true;
280  }
292 
293  template<typename Serializable>
294  void store_data(std::string const &key,Serializable const &data,
295  std::set<std::string> const &triggers=std::set<std::string>(),
296  int timeout=-1,bool notriggers=false)
297  {
298  std::string buffer;
300  store(key,buffer,triggers,timeout,notriggers);
301  }
302 
312 
313  template<typename Serializable>
314  void store_data(std::string const &key,Serializable const &data,int timeout,bool notriggers=false)
315  {
316  store_data<Serializable>(key,data,std::set<std::string>(),timeout,notriggers);
317  }
318 
319  private:
320 
321  friend class triggers_recorder;
322 
323  void add_triggers_recorder(triggers_recorder *rec);
324  void remove_triggers_recorder(triggers_recorder *rec);
325 
326 
327  void store( std::string const &key,
328  std::string const &data,
329  std::set<std::string> const &triggers,
330  int timeout,
331  bool notriggers);
332 
333  bool fetch( std::string const &key,
334  std::string &buffer,
335  bool notriggers);
336 
337  struct _data;
339  http::context *context_;
340  std::set<std::string> triggers_;
341  std::set<triggers_recorder *> recorders_;
343 
344  uint32_t page_compression_used_ : 1;
345  CPPCMS_UNUSED_MEMBER uint32_t reserved : 31;
346  };
347 
348 
349 }
350 
351 #endif
void store_data(std::string const &key, Serializable const &data, std::set< std::string > const &triggers=std::set< std::string >(), int timeout=-1, bool notriggers=false)
Definition: cache_interface.h:294
bool fetch_data(std::string const &key, Serializable &data, bool notriggers=false)
Definition: cache_interface.h:273
This class represent the central event loop of the CppCMS applications.
Definition: service.h:62
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
static void load(std::string const &serialized_object, Object &real_object)
context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information
Definition: http_context.h:47
void store_data(std::string const &key, Serializable const &data, int timeout, bool notriggers=false)
Definition: cache_interface.h:314
triggers_recorder is a class that allows you to record all triggers added in certain scope...
Definition: cache_interface.h:73
This class is the major gateway of the application to CppCMS caching abilities. Any access too cache ...
Definition: cache_interface.h:139
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15
static void save(Object const &real_object, std::string &serialized_object)