interfaceStore { /** * Retrieve an item from the cache by key. * * @param string|array $key * @return mixed */ publicfunctionget($key);
/** * Retrieve multiple items from the cache by key. * * Items not found in the cache will have a null value. * * @param array $keys * @return array */ publicfunctionmany(array$keys);
/** * Store an item in the cache for a given number of minutes. * * @param string $key * @param mixed $value * @param int $minutes * @return void */ publicfunctionput($key, $value, $minutes);
/** * Store multiple items in the cache for a given number of minutes. * * @param array $values * @param int $minutes * @return void */ publicfunctionputMany(array$values, $minutes);
/** * Increment the value of an item in the cache. * * @param string $key * @param mixed $value * @return int|bool */ publicfunctionincrement($key, $value = 1);
/** * Decrement the value of an item in the cache. * * @param string $key * @param mixed $value * @return int|bool */ publicfunctiondecrement($key, $value = 1);
/** * Store an item in the cache indefinitely. * * @param string $key * @param mixed $value * @return void */ publicfunctionforever($key, $value);
/** * Remove an item from the cache. * * @param string $key * @return bool */ publicfunctionforget($key);
/** * Remove all items from the cache. * * @return void */ publicfunctionflush();
/** * Get the cache key prefix. * * @return string */ publicfunctiongetPrefix(); }
/** * Retrieve an item from the cache by key. * * @param string|array $key * @return mixed */ publicfunctionget($key) { $value = $this->memcached->get($this->prefix.$key);
if ($this->memcached->getResultCode() == 0) { return$value; } }
/** * Retrieve multiple items from the cache by key. * * Items not found in the cache will have a null value. * * @param array $keys * @return array */ publicfunctionmany(array$keys) { $prefixedKeys = array_map(function ($key) { return$this->prefix.$key; }, $keys);
if ($this->memcached->getResultCode() != 0) { return array_fill_keys($keys, null); }
return array_combine($keys, $values); }
/** * Store an item in the cache for a given number of minutes. * * @param string $key * @param mixed $value * @param int $minutes * @return void */ publicfunctionput($key, $value, $minutes) { $this->memcached->set($this->prefix.$key, $value, $minutes * 60); }
/** * Store multiple items in the cache for a given number of minutes. * * @param array $values * @param int $minutes * @return void */ publicfunctionputMany(array$values, $minutes) { $prefixedValues = [];
$memcached = new \Memcached(); $memcached->addServer('localhost',11211); $memcachedCache = new MemcachedStore($memcached); $cacheStore = new CacheStore($memcachedCache); $cacheStore->put('site','http://LaravelAcademy.org'); dd($cacheStore->get('site'));