cache_interface.h
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
#ifndef CPPCMS_CACHE_INTERFACE_H
#define CPPCMS_CACHE_INTERFACE_H
#include <string>
#include <set>
#include <cppcms/defs.h>
#include <cppcms/serialization_classes.h>
#include <booster/noncopyable.h>
#include <booster/intrusive_ptr.h>
#include <booster/hold_ptr.h>
#include <cppcms/cstdint.h>
namespace cppcms {
namespace impl {
class base_cache;
}
namespace http {
class context;
};
class cache_interface;
class CPPCMS_API triggers_recorder : public booster::noncopyable {
public:
triggers_recorder(cache_interface &);
~triggers_recorder();
std::set<std::string> detach();
private:
friend class cache_interface;
void add(std::string const &t);
struct data;
booster::hold_ptr<data> d;
std::set<std::string> triggers_;
cache_interface *cache_;
};
class CPPCMS_API cache_interface : public booster::noncopyable {
public:
cache_interface(http::context &context);
~cache_interface();
void rise(std::string const &trigger);
void add_trigger(std::string const &trigger);
void clear();
void reset();
bool stats(unsigned &keys,unsigned &triggers);
bool has_cache();
bool nocache();
bool fetch_page(std::string const &key);
void store_page(std::string const &key,int timeout=-1);
bool fetch_frame(std::string const &key,std::string &result,bool notriggers=false);
void store_frame(std::string const &key,
std::string const &frame,
std::set<std::string> const &triggers=std::set<std::string>(),
int timeout=-1,
bool notriggers=false);
void store_frame(std::string const &key,
std::string const &frame,
int timeout,
bool notriggers=false);
template<typename Serializable>
bool fetch_data(std::string const &key,Serializable &data,bool notriggers=false)
{
std::string buffer;
if(!fetch(key,buffer,notriggers))
return false;
serialization_traits<Serializable>::load(buffer,data);
return true;
}
template<typename Serializable>
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)
{
std::string buffer;
serialization_traits<Serializable>::save(data,buffer);
store(key,buffer,triggers,timeout,notriggers);
}
template<typename Serializable>
void store_data(std::string const &key,Serializable const &data,int timeout,bool notriggers=false)
{
store_data<Serializable>(key,data,std::set<std::string>(),timeout,notriggers);
}
private:
friend class triggers_recorder;
void add_triggers_recorder(triggers_recorder *rec);
void remove_triggers_recorder(triggers_recorder *rec);
void store( std::string const &key,
std::string const &data,
std::set<std::string> const &triggers,
int timeout,
bool notriggers);
bool fetch( std::string const &key,
std::string &buffer,
bool notriggers);
struct _data;
booster::hold_ptr<_data> d;
http::context *context_;
std::set<std::string> triggers_;
std::set<triggers_recorder *> recorders_;
booster::intrusive_ptr<impl::base_cache> cache_module_;
uint32_t page_compression_used_ : 1;
uint32_t reserved : 31;
};
}
#endif
cppcms::cache_interface::store_data
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
booster::hold_ptr< data >
cppcms::cache_interface::fetch_data
bool fetch_data(std::string const &key, Serializable &data, bool notriggers=false)
Definition: cache_interface.h:264
cppcms::serialization_traits::load
static void load(std::string const &serialized_object, Object &real_object)
cppcms::http::context
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
cppcms::cache_interface::store_data
void store_data(std::string const &key, Serializable const &data, int timeout, bool notriggers=false)
Definition: cache_interface.h:305
booster::intrusive_ptr< impl::base_cache >
cppcms::triggers_recorder
triggers_recorder is a class that allows you to record all triggers added in certain scope...
Definition: cache_interface.h:71
cppcms::cache_interface
This class is the major gateway of the application to CppCMS caching abilities. Any access too cache ...
Definition: cache_interface.h:137
booster::noncopyable
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15
cppcms::serialization_traits::save
static void save(Object const &real_object, std::string &serialized_object)