Advertisement
stixlink

SMemcache

Jul 10th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Created by PhpStorm.
  5.  * User: Stixlink
  6.  * Date: 10.07.14
  7.  * Time: 18:49
  8.  */
  9. namespace wrappers;
  10.  
  11. class SMemcache implements \interfaces\ICache {
  12.  
  13.  
  14.     private $memcache;
  15.     private $memcacheConnect;
  16.     private $duration;
  17.     private $compressed;
  18.  
  19.     /**
  20.      * @param string $host
  21.      * @param int    $port
  22.      * @param int    $compressed
  23.      */
  24.     public function __construct($host = "127.0.0.1", $port = 11211, $compressed = 0) {
  25.  
  26.         $this->memcache = new \Memcache();
  27.         $this->memcacheConnect = $this->memcache->connect($host, $port);
  28.         $this->compressed = $compressed;
  29.     }
  30.  
  31.     /**
  32.      * @param array|string $key
  33.      *
  34.      * @return array|string
  35.      */
  36.     public function get($key) {
  37.  
  38.         return $this->memcache->get($key);
  39.     }
  40.  
  41.     /**
  42.      * @param string $key
  43.      * @param mixed  $value
  44.      * @param int    $duration
  45.      *
  46.      * @return bool
  47.      */
  48.     public function set($key, $value, $duration = 3600) {
  49.  
  50.         return $this->memcache->set($key, $value, $this->compressed, $duration);
  51.     }
  52.  
  53.     /**
  54.      * @param string $key
  55.      *
  56.      * @return bool
  57.      */
  58.     public function delete($key) {
  59.  
  60.         return $this->memcache->delete($key);
  61.     }
  62.  
  63.     public function __destruct() {
  64.  
  65.         $this->memcache->close();
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement