mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-03 05:41:37 +01:00
- update for PHP 5.4 compatibility
- reformat source to PSR-2 standard
This commit is contained in:
@@ -12,24 +12,25 @@
|
||||
* @package CacheResource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore {
|
||||
class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
||||
{
|
||||
/**
|
||||
* memcache instance
|
||||
* @var Memcache
|
||||
*/
|
||||
protected $memcache = null;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->memcache = new Memcache();
|
||||
$this->memcache->addServer( '127.0.0.1', 11211 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read values for a set of keys from cache
|
||||
*
|
||||
* @param array $keys list of keys to fetch
|
||||
* @return array list of values with the given keys used as indexes
|
||||
* @param array $keys list of keys to fetch
|
||||
* @return array list of values with the given keys used as indexes
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function read(array $keys)
|
||||
@@ -45,14 +46,15 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore {
|
||||
foreach ($res as $k => $v) {
|
||||
$_res[$lookup[$k]] = $v;
|
||||
}
|
||||
|
||||
return $_res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save values for a set of keys to cache
|
||||
*
|
||||
* @param array $keys list of values to save
|
||||
* @param int $expire expiration time
|
||||
* @param array $keys list of values to save
|
||||
* @param int $expire expiration time
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function write(array $keys, $expire=null)
|
||||
@@ -61,13 +63,14 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore {
|
||||
$k = sha1($k);
|
||||
$this->memcache->set($k, $v, 0, $expire);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove values from cache
|
||||
*
|
||||
* @param array $keys list of keys to delete
|
||||
* @param array $keys list of keys to delete
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function delete(array $keys)
|
||||
@@ -76,6 +79,7 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore {
|
||||
$k = sha1($k);
|
||||
$this->memcache->delete($k);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user