Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class cacheMemcache implements cacheInterface
- {
- private $memcache;
- public function put($key, $value, $ttl = 0)
- {
- $this->_memcache->add($key, $value, MEMCACHE_COMPRESSED, $ttl);
- }
- public function get($key)
- {
- return $this->_memcache->get($key);
- }
- public function remove($key)
- {
- $this->_memcache->delete($key);
- }
- public function connect(array $opts)
- {
- $opts = array_merge(array('host'=>'localhost','port'=>11211), $opts);
- $this->_memcache = new Memcache;
- if (!$this->_memcache->connect($opts['host'], $opts['port']))
- {
- throw new Exception('Connection to memcache server failed');
- }
- $this->_memcache->setCompressThreshold(20000, 0.2);
- }
- public function disconnect()
- {
- $this->_memcache->close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement