Advertisement
miraage

Untitled

Aug 23rd, 2011
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. class cacheMemcache implements cacheInterface
  2. {
  3.     private $memcache;
  4.    
  5.     public function put($key, $value, $ttl = 0)
  6.     {
  7.         $this->_memcache->add($key, $value, MEMCACHE_COMPRESSED, $ttl);
  8.     }
  9.    
  10.     public function get($key)
  11.     {
  12.         return $this->_memcache->get($key);
  13.     }
  14.    
  15.     public function remove($key)
  16.     {
  17.         $this->_memcache->delete($key);
  18.     }
  19.    
  20.     public function connect(array $opts)
  21.     {
  22.         $opts = array_merge(array('host'=>'localhost','port'=>11211), $opts);
  23.        
  24.         $this->_memcache = new Memcache;
  25.         if (!$this->_memcache->connect($opts['host'], $opts['port']))
  26.         {
  27.             throw new Exception('Connection to memcache server failed');
  28.         }
  29.         $this->_memcache->setCompressThreshold(20000, 0.2);
  30.     }
  31.    
  32.     public function disconnect()
  33.     {
  34.         $this->_memcache->close();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement