27 #require_once 'Zend/Cache/Backend/ExtendedInterface.php'; 32 #require_once 'Zend/Cache/Backend.php'; 75 'servers' => array(array(
76 'host' => self::DEFAULT_HOST,
77 'port' => self::DEFAULT_PORT,
78 'weight' => self::DEFAULT_WEIGHT,
99 if (!extension_loaded(
'memcached')) {
104 $this->_options[
'client'] = array(
105 Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
106 Memcached::OPT_HASH => Memcached::HASH_MD5,
107 Memcached::OPT_LIBKETAMA_COMPATIBLE =>
true,
112 if (isset($this->_options[
'servers'])) {
113 $value = $this->_options[
'servers'];
114 if (isset(
$value[
'host'])) {
120 $this->_memcache =
new Memcached;
123 foreach ($this->_options[
'client'] as
$name =>
$value) {
128 $optConst =
'Memcached::OPT_' . strtoupper(
$name);
129 if (defined($optConst)) {
130 $optId = constant($optConst);
132 $this->
_log(
"Unknown memcached client option '{$name}' ({$optConst})");
135 if (
null !== $optId) {
136 if (!$this->_memcache->setOption($optId,
$value)) {
137 $this->
_log(
"Setting memcached client option '{$optId}' failed");
144 foreach ($this->_options[
'servers'] as $server) {
145 if (!array_key_exists(
'port', $server)) {
148 if (!array_key_exists(
'weight', $server)) {
152 $servers[] = array($server[
'host'], $server[
'port'], $server[
'weight']);
154 $this->_memcache->addServers($servers);
164 public function load(
$id, $doNotTestCacheValidity =
false)
166 $tmp = $this->_memcache->get(
$id);
167 if (isset($tmp[0])) {
181 $tmp = $this->_memcache->get(
$id);
182 if (isset($tmp[0], $tmp[1])) {
200 public function save(
$data,
$id, $tags = array(), $specificLifetime =
false)
207 $rsCode = $this->_memcache->getResultCode();
208 $rsMsg = $this->_memcache->getResultMessage();
209 $this->
_log(
"Memcached::set() failed: [{$rsCode}] {$rsMsg}");
212 if (count($tags) > 0) {
213 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
225 public function remove(
$id)
227 return $this->_memcache->delete(
$id);
249 return $this->_memcache->flush();
252 $this->
_log(
"Zend_Cache_Backend_Libmemcached::clean() : CLEANING_MODE_OLD is unsupported by the Libmemcached backend");
257 $this->
_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND);
284 parent::setDirectives($directives);
286 if ($lifetime > 2592000) {
288 $this->
_log(
'memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
290 if ($lifetime ===
null) {
292 parent::setDirectives(array(
'lifetime' => 0));
303 $this->
_log(
"Zend_Cache_Backend_Libmemcached::save() : getting the list of cache ids is unsupported by the Libmemcached backend");
314 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
328 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
342 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
356 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
368 $mems = $this->_memcache->getStats();
369 if ($mems ===
false) {
375 foreach ($mems as $key => $mem) {
376 if ($mem ===
false) {
377 $this->
_log(
'can\'t get stat from ' . $key);
381 $eachSize = $mem[
'limit_maxbytes'];
382 $eachUsed = $mem[
'bytes'];
383 if ($eachUsed > $eachSize) {
384 $eachUsed = $eachSize;
387 $memSize += $eachSize;
388 $memUsed += $eachUsed;
391 if ($memSize ===
null || $memUsed ===
null) {
395 return ((
int) (100. * ($memUsed / $memSize)));
411 $tmp = $this->_memcache->get(
$id);
412 if (isset($tmp[0], $tmp[1], $tmp[2])) {
417 'expire' => $mtime + $lifetime,
435 $tmp = $this->_memcache->get(
$id);
436 if (isset($tmp[0], $tmp[1], $tmp[2])) {
440 $newLifetime = $lifetime - (
time() - $mtime) + $extraLifetime;
441 if ($newLifetime <=0) {
445 if (!(
$result = $this->_memcache->replace(
$id, array(
$data,
time(), $newLifetime), $newLifetime))) {
448 $rsCode = $this->_memcache->getResultCode();
449 $rsMsg = $this->_memcache->getResultMessage();
450 $this->
_log(
"Memcached::set() failed: [{$rsCode}] {$rsMsg}");
475 'automatic_cleaning' =>
false,
477 'expired_read' =>
false,
479 'infinite_lifetime' =>
false,
touch($id, $extraLifetime)
_log($message, $priority=4)
getIdsMatchingAnyTags($tags=array())
getIdsMatchingTags($tags=array())
const CLEANING_MODE_NOT_MATCHING_TAG
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
getIdsNotMatchingTags($tags=array())
static throwException($msg, Exception $e=null)
save($data, $id, $tags=array(), $specificLifetime=false)
clean($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
const CLEANING_MODE_MATCHING_ANY_TAG
load($id, $doNotTestCacheValidity=false)
const CLEANING_MODE_MATCHING_TAG
setDirectives($directives)
getLifetime($specificLifetime)
const TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND
isAutomaticCleaningAvailable()
const TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND
__construct(array $options=array())
if(!isset($_GET['name'])) $name