Menu

[r1123]: / framework / branches / refactoring / cache_pool.cpp  Maximize  Restore  History

Download this file

53 lines (46 with data), 1.4 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
#define CPPCMS_SOURCE
#include "cache_pool.h"
#include "cache_storage.h"
#include "base_cache.h"
#include "cppcms_error.h"
#include "json.h"
namespace cppcms {
struct cache_pool::data {
intrusive_ptr<impl::base_cache> module;
};
cache_pool::cache_pool(json::value const &settings) :
d(new data())
{
std::string type = settings.get("cache.backend","none");
if(type == "none" )
return;
if(type=="thread_shared") {
if(settings.get("service.worker_processes",0)>1)
throw cppcms_error(
"Can't use `thread_shared' backend with more then one process ether set "
"service.worker_processes to 0 or 1 or use cache.backend=\"process_shared\"");
unsigned items = settings.get("cache.limit",64);
d->module=impl::thread_cache_factory(items);
}
else if(type=="process_shared") {
#ifdef CPPCMS_WIN32
throw cppcms_error("The 'process_shared' backend is not supported under MS Windows and Cygwin platforms");
#else
size_t memory = settings.get("cache.memory",16384) * 1024;
if(memory < 65536)
throw cppcms_error("'process_shared' cache backend requires at least 64 KB of cache memory: cache.memory >= 64");
d->module=impl::process_cache_factory(memory);
#endif
}
else {
throw cppcms_error("Unsupported cache backend `" + type + "'");
}
}
cache_pool::~cache_pool()
{
}
intrusive_ptr<impl::base_cache> cache_pool::get()
{
return d->module;
}
} // cppcms
MongoDB Logo MongoDB