Skip to content

Commit

Permalink
Merge pull request #11323 from ifsnow/2.0.x-fix-issue-11322
Browse files Browse the repository at this point in the history
Fixed cache backends bug #11322
  • Loading branch information
sergeyklay committed Jan 21, 2016
2 parents e7e9c93 + 9320aad commit 02e0814
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed `Phalcon\Translate\Adapter\Gettext::setLocale` bug[#11311](https://github.com/phalcon/cphalcon/issues/11311) related to the incorrect setting locale
- Added ability to persistent connection in `Phalcon\Queue\Beanstalk::connect`
- Fixed `Phalcon\Http\Response::redirect` bug[#11324](https://github.com/phalcon/cphalcon/issues/11324). Incorrect initialization local array of status codes
- Fixed cache backends bug[#11322](https://github.com/phalcon/cphalcon/issues/11322) related to saving number 0

# [2.0.9](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.9) (2015-11-24)
- Fixed bug that double serializes data using Redis adapter
Expand Down
4 changes: 2 additions & 2 deletions phalcon/cache/backend/file.zep
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class File extends Backend implements BackendInterface
{
var lastKey, frontend, cacheDir, isBuffering, cacheFile, cachedContent, preparedContent, status;

if !keyName {
if keyName === null {
let lastKey = this->_lastKey;
} else {
let lastKey = this->_prefix . this->getKey(keyName);
Expand All @@ -194,7 +194,7 @@ class File extends Backend implements BackendInterface

let cacheFile = cacheDir . lastKey;

if !content {
if content === null {
let cachedContent = frontend->getContent();
} else {
let cachedContent = content;
Expand Down
6 changes: 3 additions & 3 deletions phalcon/cache/backend/libmemcached.zep
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Libmemcached extends Backend implements BackendInterface
var lastKey, frontend, memcache, cachedContent, preparedContent, tmp, tt1, success, options,
specialKey, keys, isBuffering;

if !keyName {
if keyName === null {
let lastKey = this->_lastKey;
} else {
let lastKey = this->_prefix . keyName;
Expand All @@ -188,7 +188,7 @@ class Libmemcached extends Backend implements BackendInterface
let memcache = this->_memcache;
}

if !content {
if content === null {
let cachedContent = frontend->getContent();
} else {
let cachedContent = content;
Expand All @@ -201,7 +201,7 @@ class Libmemcached extends Backend implements BackendInterface
let preparedContent = frontend->beforeStore(cachedContent);
}

if !lifetime {
if lifetime === null {
let tmp = this->_lastLifetime;

if !tmp {
Expand Down
6 changes: 3 additions & 3 deletions phalcon/cache/backend/memcache.zep
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Memcache extends Backend implements BackendInterface
var lastKey, frontend, memcache, cachedContent, preparedContent, tmp, ttl, success, options,
specialKey, keys, isBuffering;

if !keyName {
if keyName === null {
let lastKey = this->_lastKey;
} else {
let lastKey = this->_prefix . keyName;
Expand All @@ -183,7 +183,7 @@ class Memcache extends Backend implements BackendInterface
let memcache = this->_memcache;
}

if typeof content == "null" {
if content === null {
let cachedContent = frontend->getContent();
} else {
let cachedContent = content;
Expand All @@ -194,7 +194,7 @@ class Memcache extends Backend implements BackendInterface
*/
let preparedContent = frontend->beforeStore(cachedContent);

if typeof lifetime == "null" {
if lifetime === null {
let tmp = this->_lastLifetime;

if !tmp {
Expand Down
6 changes: 3 additions & 3 deletions phalcon/cache/backend/mongo.zep
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class Mongo extends Backend implements BackendInterface
let conditions = [];
let data = [];

if !keyName {
if keyName === null {
let lastkey = this->_lastKey;
} else {
let prefix = this->_prefix;
Expand All @@ -206,7 +206,7 @@ class Mongo extends Backend implements BackendInterface
}

let frontend = this->_frontend;
if !content {
if content === null {
let cachedContent = frontend->getContent();
} else {
let cachedContent = content;
Expand All @@ -216,7 +216,7 @@ class Mongo extends Backend implements BackendInterface
let preparedContent = frontend->beforeStore(cachedContent);
}

if !lifetime {
if lifetime === null {
let tmp = this->_lastLifetime;
if !tmp {
let ttl = frontend->getLifetime();
Expand Down
6 changes: 3 additions & 3 deletions phalcon/cache/backend/redis.zep
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class Redis extends Backend implements BackendInterface
var prefixedKey, lastKey, prefix, frontend, redis, cachedContent, preparedContent,
tmp, tt1, success, options, specialKey, isBuffering;

if !keyName {
if keyName === null {
let lastKey = this->_lastKey;
let prefixedKey = substr(lastKey, 5);
} else {
Expand All @@ -208,7 +208,7 @@ class Redis extends Backend implements BackendInterface
let redis = this->_redis;
}

if !content {
if content === null {
let cachedContent = frontend->getContent();
} else {
let cachedContent = content;
Expand All @@ -221,7 +221,7 @@ class Redis extends Backend implements BackendInterface
let preparedContent = frontend->beforeStore(cachedContent);
}

if !lifetime {
if lifetime === null {
let tmp = this->_lastLifetime;

if !tmp {
Expand Down
6 changes: 3 additions & 3 deletions phalcon/cache/backend/xcache.zep
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Xcache extends Backend implements BackendInterface
var lastKey, frontend, cachedContent, preparedContent, tmp, tt1, success, isBuffering,
options, keys, specialKey;

if !keyName {
if keyName === null {
let lastKey = this->_lastKey;
} else {
let lastKey = "_PHCX" . this->_prefix . keyName;
Expand All @@ -120,7 +120,7 @@ class Xcache extends Backend implements BackendInterface
}

let frontend = this->_frontend;
if !content {
if content === null {
let cachedContent = frontend->getContent();
} else {
let cachedContent = content;
Expand All @@ -133,7 +133,7 @@ class Xcache extends Backend implements BackendInterface
/**
* Take the lifetime from the frontend or read it from the set in start()
*/
if !lifetime {
if lifetime === null {
let tmp = this->_lastLifetime;
if !tmp {
let tt1 = frontend->getLifetime();
Expand Down
14 changes: 14 additions & 0 deletions unit-tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ public function testDataFileCache()
//Delete
$this->assertTrue($cache->delete('test-data'));

// Save & Get : zero string, zero number, false
$testSets = array(
'test-zero-data' => '0',
'test-0-data' => 0,
'test-false-data' => false
);

foreach($testSets as $key => $value) {
$cache->save($key, $value);
$this->assertTrue(file_exists('unit-tests/cache/'.$cache->getKey($key)));

$cachedContent = $cache->get($key);
$this->assertEquals($cachedContent, $value);
}
}

public function testDataFileCacheIncrement()
Expand Down

0 comments on commit 02e0814

Please sign in to comment.