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  namespace impl {
24  class base_cache;
25  }
26  namespace http {
27  class context;
28  };
29 
30  class cache_interface;
31 
71  class CPPCMS_API triggers_recorder : public booster::noncopyable {
72  public:
85  std::set<std::string> detach();
86  private:
87  friend class cache_interface;
88  void add(std::string const &t);
89  struct data;
91  std::set<std::string> triggers_;
92  cache_interface *cache_;
93  };
94 
134 
135 
136 
137  class CPPCMS_API cache_interface : public booster::noncopyable {
138  public:
139 
145  cache_interface(http::context &context);
146  ~cache_interface();
147 
149 
153  void rise(std::string const &trigger);
154 
158 
159  void add_trigger(std::string const &trigger);
160 
164  void clear();
165 
169  void reset();
170 
179  bool stats(unsigned &keys,unsigned &triggers);
180 
184  bool has_cache();
185 
189  bool nocache();
190 
195  bool fetch_page(std::string const &key);
196 
207 
208  void store_page(std::string const &key,int timeout=-1);
209 
220  bool fetch_frame(std::string const &key,std::string &result,bool notriggers=false);
221 
233  void store_frame(std::string const &key,
234  std::string const &frame,
235  std::set<std::string> const &triggers=std::set<std::string>(),
236  int timeout=-1,
237  bool notriggers=false);
238 
248  void store_frame(std::string const &key,
249  std::string const &frame,
250  int timeout,
251  bool notriggers=false);
252 
263  template<typename Serializable>
264  bool fetch_data(std::string const &key,Serializable &data,bool notriggers=false)
265  {
266  std::string buffer;
267  if(!fetch(key,buffer,notriggers))
268  return false;
270  return true;
271  }
283 
284  template<typename Serializable>
285  void store_data(std::string const &key,Serializable const &data,
286  std::set<std::string> const &triggers=std::set<std::string>(),
287  int timeout=-1,bool notriggers=false)
288  {
289  std::string buffer;
291  store(key,buffer,triggers,timeout,notriggers);
292  }
293 
303 
304  template<typename Serializable>
305  void store_data(std::string const &key,Serializable const &data,int timeout,bool notriggers=false)
306  {
307  store_data<Serializable>(key,data,std::set<std::string>(),timeout,notriggers);
308  }
309 
310  private:
311 
312  friend class triggers_recorder;
313 
314  void add_triggers_recorder(triggers_recorder *rec);
315  void remove_triggers_recorder(triggers_recorder *rec);
316 
317 
318  void store( std::string const &key,
319  std::string const &data,
320  std::set<std::string> const &triggers,
321  int timeout,
322  bool notriggers);
323 
324  bool fetch( std::string const &key,
325  std::string &buffer,
326  bool notriggers);
327 
328  struct _data;
330  http::context *context_;
331  std::set<std::string> triggers_;
332  std::set<triggers_recorder *> recorders_;
334 
335  uint32_t page_compression_used_ : 1;
336  uint32_t reserved : 31;
337  };
338 
339 
340 }
341 
342 #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:285
bool fetch_data(std::string const &key, Serializable &data, bool notriggers=false)
Definition: cache_interface.h:264
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:45
void store_data(std::string const &key, Serializable const &data, int timeout, bool notriggers=false)
Definition: cache_interface.h:305
triggers_recorder is a class that allows you to record all triggers added in certain scope...
Definition: cache_interface.h:71
This class is the major gateway of the application to CppCMS caching abilities. Any access too cache ...
Definition: cache_interface.h:137
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)