32#include <libmemcached/memcached.h>
34#ifdef LIBMEMCACHED_VERSION_STRING
35typedef memcached_return memcached_return_t;
49 memcached_return_t _rc;
52 memcached_server_st *_servers;
70 Memcache(
const std::string& servernames =
"localhost",
unsigned int timeout = 3600 ) {
78 _memc = memcached_create(NULL);
81 _servers = memcached_servers_parse( servernames.c_str() );
85 _rc = memcached_behavior_set( _memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1 );
86 _rc = memcached_behavior_set( _memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1 );
87 _rc = memcached_behavior_set( _memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1 );
88 _rc = memcached_behavior_set( _memc, MEMCACHED_BEHAVIOR_NOREPLY, 1 );
91 _rc = memcached_server_push( _memc, _servers );
92 if(_rc == MEMCACHED_SUCCESS ) _connected =
true;
93 else _connected =
false;
95 if( memcached_server_count(_memc) > 0 ) _connected =
true;
96 else _connected =
false;
103 if( _servers ) memcached_server_free(_servers);
104 if( _memc ) memcached_free(_memc);
113 void store(
const std::string& key,
void* data,
unsigned int length ){
115 if( !_connected )
return;
117 std::string k =
"iipsrv::" + key;
118 _rc = memcached_set( _memc, k.c_str(), k.length(),
130 if( !_connected )
return NULL;
133 std::string k =
"iipsrv::" + key;
134 return memcached_get( _memc, k.c_str(), k.length(), &_length, &flags, &_rc );
140 return memcached_strerror( _memc, _rc );
145 unsigned int length(){
return _length; };
Cache to store raw tile data.
Definition: Memcached.h:40
void store(const std::string &key, void *data, unsigned int length)
Insert data into our cache.
Definition: Memcached.h:113
bool connected()
Tell us whether we are connected to any memcached servers.
Definition: Memcached.h:149
char * retrieve(const std::string &key)
Retrieve data from our cache.
Definition: Memcached.h:128
Memcache(const std::string &servernames="localhost", unsigned int timeout=3600)
Constructor.
Definition: Memcached.h:70
const char * error()
Get error string.
Definition: Memcached.h:139
~Memcache()
Destructor.
Definition: Memcached.h:101
unsigned int length()
Return the number of bytes in the result.
Definition: Memcached.h:145