27 #require_once 'Zend/Cache/Backend/ExtendedInterface.php'; 32 #require_once 'Zend/Cache/Backend.php'; 92 'servers' => array(array(
93 'host' => self::DEFAULT_HOST,
94 'port' => self::DEFAULT_PORT,
95 'persistent' => self::DEFAULT_PERSISTENT,
96 'weight' => self::DEFAULT_WEIGHT,
97 'timeout' => self::DEFAULT_TIMEOUT,
98 'retry_interval' => self::DEFAULT_RETRY_INTERVAL,
99 'status' => self::DEFAULT_STATUS,
100 'failure_callback' => self::DEFAULT_FAILURE_CALLBACK
102 'compression' =>
false,
103 'compatibility' =>
false,
122 if (!extension_loaded(
'memcache')) {
126 if (isset($this->_options[
'servers'])) {
127 $value= $this->_options[
'servers'];
128 if (isset(
$value[
'host'])) {
134 $this->_memcache =
new Memcache;
135 foreach ($this->_options[
'servers'] as $server) {
136 if (!array_key_exists(
'port', $server)) {
139 if (!array_key_exists(
'persistent', $server)) {
142 if (!array_key_exists(
'weight', $server)) {
145 if (!array_key_exists(
'timeout', $server)) {
148 if (!array_key_exists(
'retry_interval', $server)) {
151 if (!array_key_exists(
'status', $server)) {
154 if (!array_key_exists(
'failure_callback', $server)) {
157 if ($this->_options[
'compatibility']) {
159 $this->_memcache->addServer($server[
'host'], $server[
'port'], $server[
'persistent'],
160 $server[
'weight'], $server[
'timeout'],
161 $server[
'retry_interval']);
163 $this->_memcache->addServer($server[
'host'], $server[
'port'], $server[
'persistent'],
164 $server[
'weight'], $server[
'timeout'],
165 $server[
'retry_interval'],
166 $server[
'status'], $server[
'failure_callback']);
178 public function load(
$id, $doNotTestCacheValidity =
false)
180 $tmp = $this->_memcache->get(
$id);
181 if (is_array($tmp) && isset($tmp[0])) {
195 $tmp = $this->_memcache->get(
$id);
196 if (is_array($tmp)) {
214 public function save(
$data,
$id, $tags = array(), $specificLifetime =
false)
217 if ($this->_options[
'compression']) {
218 $flag = MEMCACHE_COMPRESSED;
226 if (count($tags) > 0) {
227 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
239 public function remove(
$id)
241 return $this->_memcache->delete(
$id, 0);
263 return $this->_memcache->flush();
266 $this->
_log(
"Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend");
271 $this->
_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND);
298 parent::setDirectives($directives);
300 if ($lifetime > 2592000) {
302 $this->
_log(
'memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
304 if ($lifetime ===
null) {
306 parent::setDirectives(array(
'lifetime' => 0));
317 $this->
_log(
"Zend_Cache_Backend_Memcached::save() : getting the list of cache ids is unsupported by the Memcache backend");
328 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
342 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
356 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
370 $this->
_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
382 $mems = $this->_memcache->getExtendedStats();
386 foreach ($mems as $key => $mem) {
387 if ($mem ===
false) {
388 $this->
_log(
'can\'t get stat from ' . $key);
392 $eachSize = $mem[
'limit_maxbytes'];
398 $eachUsed = isset($mem[
'bytes']) ? $mem[
'bytes'] : $mem[
'mem_used'];
399 if ($eachUsed > $eachSize) {
400 $eachUsed = $eachSize;
403 $memSize += $eachSize;
404 $memUsed += $eachUsed;
407 if ($memSize ===
null || $memUsed ===
null) {
411 return ((
int) (100. * ($memUsed / $memSize)));
427 $tmp = $this->_memcache->get(
$id);
428 if (is_array($tmp)) {
431 if (!isset($tmp[2])) {
438 'expire' => $mtime + $lifetime,
455 if ($this->_options[
'compression']) {
456 $flag = MEMCACHE_COMPRESSED;
460 $tmp = $this->_memcache->get(
$id);
461 if (is_array($tmp)) {
464 if (!isset($tmp[2])) {
470 $newLifetime = $lifetime - (
time() - $mtime) + $extraLifetime;
471 if ($newLifetime <=0) {
475 if (!(
$result = $this->_memcache->replace(
$id, array(
$data,
time(), $newLifetime), $flag, $newLifetime))) {
476 $result = $this->_memcache->set(
$id, array(
$data,
time(), $newLifetime), $flag, $newLifetime);
500 'automatic_cleaning' =>
false,
502 'expired_read' =>
false,
504 'infinite_lifetime' =>
false,
setDirectives($directives)
const DEFAULT_FAILURE_CALLBACK
const DEFAULT_RETRY_INTERVAL
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND
touch($id, $extraLifetime)
isAutomaticCleaningAvailable()
getIdsMatchingAnyTags($tags=array())
_log($message, $priority=4)
save($data, $id, $tags=array(), $specificLifetime=false)
const CLEANING_MODE_NOT_MATCHING_TAG
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
__construct(array $options=array())
clean($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
static throwException($msg, Exception $e=null)
getIdsNotMatchingTags($tags=array())
const CLEANING_MODE_MATCHING_ANY_TAG
load($id, $doNotTestCacheValidity=false)
const CLEANING_MODE_MATCHING_TAG
getLifetime($specificLifetime)
getIdsMatchingTags($tags=array())