-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemcache_proxy.h
37 lines (30 loc) · 992 Bytes
/
memcache_proxy.h
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
#ifndef _VAE_THRIFT_MEMCACHE_PROXY_H_
#define _VAE_THRIFT_MEMCACHE_PROXY_H_
#include <string>
#include <boost/smart_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <libmemcached/memcached.hpp>
enum {
MEMCACHE_POOL_FREE,
MEMCACHE_POOL_INUSE
};
typedef std::map<memcache::Memcache *, short> MemcachePool;
class MemcacheProxy {
std::string connectString;
MemcachePool connPool;
boost::mutex poolMutex;
boost::condition_variable cond;
int availableConnections;
public:
MemcacheProxy(std::string connectString, int workers);
~MemcacheProxy();
std::string get(const std::string key, const int32_t flags);
void set(const std::string key, const std::string value, const int32_t flags, const int32_t expireInterval);
void remove(const std::string key);
private:
memcache::Memcache *createConnection();
boost::shared_ptr<memcache::Memcache> getConnection();
void freeConnection(memcache::Memcache *con);
};
#endif