00001
00002
00003
00004
00005
00006
00008 #ifndef CPPCMS_CACHE_INTERFACE_H
00009 #define CPPCMS_CACHE_INTERFACE_H
00010
00011 #include <string>
00012 #include <set>
00013
00014 #include <cppcms/defs.h>
00015 #include <cppcms/serialization_classes.h>
00016 #include <booster/noncopyable.h>
00017 #include <booster/intrusive_ptr.h>
00018 #include <booster/hold_ptr.h>
00019 #include <cppcms/cstdint.h>
00020
00021 namespace cppcms {
00022
00023 namespace impl {
00024 class base_cache;
00025 }
00026 namespace http {
00027 class context;
00028 };
00029
00030 class cache_interface;
00031
00071 class CPPCMS_API triggers_recorder : public booster::noncopyable {
00072 public:
00076 triggers_recorder(cache_interface &);
00080 ~triggers_recorder();
00085 std::set<std::string> detach();
00086 private:
00087 friend class cache_interface;
00088 void add(std::string const &t);
00089 struct data;
00090 booster::hold_ptr<data> d;
00091 std::set<std::string> triggers_;
00092 cache_interface *cache_;
00093 };
00094
00134
00135
00136
00137 class CPPCMS_API cache_interface : public booster::noncopyable {
00138 public:
00139
00145 cache_interface(http::context &context);
00146 ~cache_interface();
00147
00149
00153 void rise(std::string const &trigger);
00154
00158
00159 void add_trigger(std::string const &trigger);
00160
00164 void clear();
00165
00169 void reset();
00170
00179 bool stats(unsigned &keys,unsigned &triggers);
00180
00184 bool has_cache();
00185
00189 bool nocache();
00190
00195 bool fetch_page(std::string const &key);
00196
00207
00208 void store_page(std::string const &key,int timeout=-1);
00209
00220 bool fetch_frame(std::string const &key,std::string &result,bool notriggers=false);
00221
00233 void store_frame(std::string const &key,
00234 std::string const &frame,
00235 std::set<std::string> const &triggers=std::set<std::string>(),
00236 int timeout=-1,
00237 bool notriggers=false);
00238
00248 void store_frame(std::string const &key,
00249 std::string const &frame,
00250 int timeout,
00251 bool notriggers=false);
00252
00263 template<typename Serializable>
00264 bool fetch_data(std::string const &key,Serializable &data,bool notriggers=false)
00265 {
00266 std::string buffer;
00267 if(!fetch(key,buffer,notriggers))
00268 return false;
00269 serialization_traits<Serializable>::load(buffer,data);
00270 return true;
00271 }
00283
00284 template<typename Serializable>
00285 void store_data(std::string const &key,Serializable const &data,
00286 std::set<std::string> const &triggers=std::set<std::string>(),
00287 int timeout=-1,bool notriggers=false)
00288 {
00289 std::string buffer;
00290 serialization_traits<Serializable>::save(data,buffer);
00291 store(key,buffer,triggers,timeout,notriggers);
00292 }
00293
00303
00304 template<typename Serializable>
00305 void store_data(std::string const &key,Serializable const &data,int timeout,bool notriggers=false)
00306 {
00307 store_data<Serializable>(key,data,std::set<std::string>(),timeout,notriggers);
00308 }
00309
00310 private:
00311
00312 friend class triggers_recorder;
00313
00314 void add_triggers_recorder(triggers_recorder *rec);
00315 void remove_triggers_recorder(triggers_recorder *rec);
00316
00317
00318 void store( std::string const &key,
00319 std::string const &data,
00320 std::set<std::string> const &triggers,
00321 int timeout,
00322 bool notriggers);
00323
00324 bool fetch( std::string const &key,
00325 std::string &buffer,
00326 bool notriggers);
00327
00328 struct _data;
00329 booster::hold_ptr<_data> d;
00330 http::context *context_;
00331 std::set<std::string> triggers_;
00332 std::set<triggers_recorder *> recorders_;
00333 booster::intrusive_ptr<impl::base_cache> cache_module_;
00334
00335 uint32_t page_compression_used_ : 1;
00336 uint32_t reserved : 31;
00337 };
00338
00339
00340 }
00341
00342 #endif