Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Memory
- {
- private static $_instance = null;
- private $_memcached = null;
- private $_status = false;
- private $_defaultExp;
- private $_prefix = "rs";
- private function __construct()
- {
- $memcached = new Memcached;
- $host = '127.0.0.1';
- $port = '11211';
- $isMemcacheAvailable = $memcached->addServer($host,$port);
- if ($isMemcacheAvailable) {
- $this->_status = true;
- $this->_memcached = $memcached;
- }
- $this->_defaultExp = 60*60*24*7;
- }
- public static function getInstance()
- {
- if(!isset(static::$_instance)){
- static::$_instance = new Memory();
- }
- return static::$_instance;
- }
- public function active()
- {
- return $this->_status;
- }
- public function get($key)
- {
- return $this->_memcached->get(str_replace(' ','_',$this->_prefix . '_' . $key));
- }
- public function forget($key)
- {
- return $this->_memcached->delete(str_replace(' ','_',$this->_prefix . '_' . $key));
- }
- public function set($key,$value,$expiration = null)
- {
- $this->_memcached->set(str_replace(' ','_',$this->_prefix . '_' . $key),$value,$expiration);
- }
- public function error()
- {
- return $this->_memcached->getResultCode();
- }
- }
Add Comment
Please, Sign In to add comment