namespace Ace; use IlluminateCacheStoreInterface; use IlluminateCacheTaggableStore;
class AceMemcachedStore extends TaggableStore implements StoreInterface {
protected $memcached; protected $prefix;
public function __construct($space, $prefix = "") { $this->memcached = Alibaba::Cache($space); $this->prefix = strlen($prefix) > 0 ? $prefix.":" : ""; }
/** * Retrieve an item from the cache by key. * * @param string $key * @return mixed */ public function get($key) { $value = $this->memcached->get($this->prefix.$key); if(is_bool($value) && $value === false) { return null; } return $value; }
/** * Store an item in the cache for a given number of minutes. * * @param string $key * @param mixed $value * @param int $minutes * @return boolean */ public function put($key, $value, $minutes) { return $this->memcached->set($this->prefix.$key, $value, $minutes); }
/** * Increment the value of an item in the cache. * * @param string $key * @param mixed $value * @return boolean */ public function increment($key, $value = 1) { return $this->memcached->increment($this->prefix.$key, $value); }
/** * Decrement the value of an item in the cache. * * @param string $key * @param mixed $value * @return boolean */ public function decrement($key, $value = 1) { return $this->memcached->decrement($this->prefix.$key, $value); }
/** * Store an item in the cache indefinitely. * * @param string $key * @param mixed $value * @return boolean */ public function forever($key, $value) { return $this->memcached->set($key, $value, 0); }
/** * Remove an item from the cache. * * @param string $key * @return boolean */ public function forget($key) { return $this->memcached->delete($this->prefix.$key); }
/** * Remove all items from the cache. * * @return void */ public function flush() { //$this->memcached->flush(); return false; }
public function getMemcached() { return $this->memcached; } /** * Get the cache key prefix. * * @return string */ public function getPrefix() { return $this->prefix; } }