Menu

[r471]: / framework / trunk / cache_interface.cpp  Maximize  Restore  History

Download this file

148 lines (127 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "cache_interface.h"
#include "worker_thread.h"
#include "global_config.h"
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <sstream>
#include <iostream>
#include "manager.h"
namespace cppcms {
using namespace std;
void deflate(string const &text,ostream &stream,long level,long length)
{
using namespace boost::iostreams;
gzip_params params;
if(level!=-1){
params.level=level;
}
filtering_ostream zstream;
if(length!=-1){
zstream.push(gzip_compressor(params,length));
}
else {
zstream.push(gzip_compressor(params));
}
zstream.push(stream);
zstream<<text;
}
string deflate(string const &text,long level,long length)
{
ostringstream sstream;
deflate(text,sstream,level,length);
return sstream.str();
}
bool cache_iface::fetch_page(string const &key)
{
if(!cms->caching_module) return false;
string tmp;
if(cms->caching_module->fetch_page(key,tmp,cms->gzip)) {
cms->cout<<tmp;
cms->gzip_done=true;
return true;
}
return false;
}
void cache_iface::store_page(string const &key,time_t timeout)
{
if(!cms->caching_module) return;
archive a;
long level=cms->app.config.lval("gzip.level",-1);
long length=cms->app.config.lval("gzip.buffer",-1);
string tmp=cms->out_buf.str();
cms->out_buf.str("");
string compr=deflate(tmp,level,length);
a<<tmp<<compr;
if(cms->gzip){
cms->cout<<compr;
cms->gzip_done=true;
}
cms->caching_module->store(key,triggers,timeout,a);
}
void cache_iface::add_trigger(string const &t)
{
if(!cms->caching_module) return;
triggers.insert(t);
}
void cache_iface::rise(string const &t)
{
if(!cms->caching_module) return;
cms->caching_module->rise(t);
}
bool cache_iface::fetch_data(string const &key,serializable &data)
{
if(!cms->caching_module) return false;
archive a;
set<string> new_trig;
if(cms->caching_module->fetch(key,a,new_trig)) {
data.load(a);
triggers.insert(new_trig.begin(),new_trig.end());
return true;
}
return false;
}
void cache_iface::store_data(string const &key,serializable const &data,
set<string> const &triggers,
time_t timeout)
{
if(!cms->caching_module) return;
archive a;
data.save(a);
this->triggers.insert(triggers.begin(),triggers.end());
cms->caching_module->store(key,triggers,timeout,a);
}
bool cache_iface::fetch_frame(string const &key,string &result)
{
if(!cms->caching_module) return false;
archive a;
set<string> new_trig;
if(cms->caching_module->fetch(key,a,new_trig)) {
a>>result;
triggers.insert(new_trig.begin(),new_trig.end());
return true;
}
return false;
}
void cache_iface::store_frame(string const &key,string const &data,
set<string> const &triggers,
time_t timeout)
{
if(!cms->caching_module) return;
archive a;
a<<data;
this->triggers.insert(triggers.begin(),triggers.end());
cms->caching_module->store(key,triggers,timeout,a);
}
void cache_iface::clear()
{
if(cms->caching_module)
cms->caching_module->clear();
}
bool cache_iface::stats(unsigned &k,unsigned &t)
{
if(!cms->caching_module)
return false;
cms->caching_module->stats(k,t);
return true;
}
} // End of namespace cppcms
MongoDB Logo MongoDB