Skip to content

Commit 4c6cde9

Browse files
committed
Merge pull request #124 from ingatlancom/sfMemcacheCache
sfMemcacheCache fix
2 parents 73786d9 + fcb3645 commit 4c6cde9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ matrix:
1919
# faster builds on new travis setup not using sudo
2020
sudo: false
2121

22+
services:
23+
- memcached
24+
2225
# cache vendor dirs
2326
cache:
2427
directories:
@@ -30,6 +33,7 @@ install:
3033

3134
before_script:
3235
- sh -c 'if [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ] && [ $(php -r "echo PHP_MAJOR_VERSION;") -le 5 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
36+
- sh -c 'if [ $(php -r "echo PHP_RELEASE_VERSION;") -le 98 ] && [ $(php -r "echo PHP_MAJOR_VERSION;") -le 5 ]; then echo "extension = memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
3337
- composer install
3438

3539
script:

data/bin/check_configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ function_exists('xcache_set')
9797
check(!ini_get('register_globals'), 'php.ini has register_globals set to off', 'Set it to off in php.ini', false);
9898
check(!ini_get('session.auto_start'), 'php.ini has session.auto_start set to off', 'Set it to off in php.ini', false);
9999

100+
check(class_exists('Memcache'), 'Memcache is available', 'You must have memcache installed and enabled to use sfMemcacheCache class.', false);
101+
100102
if (!is_cli())
101103
{
102104
echo '</pre></body></html>';

lib/cache/sfMemcacheCache.class.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,21 @@ public function get($key, $default = null)
9292
{
9393
$value = $this->memcache->get($this->getOption('prefix').$key);
9494

95-
return false === $value ? $default : $value;
95+
return (false === $value && false === $this->getMetadata($key)) ? $default : $value;
9696
}
9797

9898
/**
9999
* @see sfCache
100100
*/
101101
public function has($key)
102102
{
103-
return !(false === $this->memcache->get($this->getOption('prefix').$key));
103+
if (false === $this->memcache->get($this->getOption('prefix') . $key))
104+
{
105+
// if there is metadata, $key exists with a false value
106+
return !(false === $this->getMetadata($key));
107+
}
108+
109+
return true;
104110
}
105111

106112
/**
@@ -232,7 +238,7 @@ protected function getMetadata($key)
232238
*/
233239
protected function setMetadata($key, $lifetime)
234240
{
235-
$this->memcache->set($this->getOption('prefix').'_metadata'.self::SEPARATOR.$key, array('lastModified' => time(), 'timeout' => time() + $lifetime), false, $lifetime);
241+
$this->memcache->set($this->getOption('prefix').'_metadata'.self::SEPARATOR.$key, array('lastModified' => time(), 'timeout' => time() + $lifetime), false, time() + $lifetime);
236242
}
237243

238244
/**

0 commit comments

Comments
 (0)