diff --git a/CHANGELOG.md b/CHANGELOG.md index 783503b45dd..c747b31857f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ # [3.0.1](https://github.com/phalcon/cphalcon/releases/tag/v3.0.1) (2016-XX-XX) +- Fixed Phalcon\Cache\Backend\Redis::flush in order to flush cache correctly +- Add the \_lastKey update when call `save` method for all backend cache [#12050](https://github.com/phalcon/cphalcon/issues/12050) - Fixed `Phalcon\Cache\Backend\Redis::flush` in order to flush cache correctly - Fixed `Phalcon\Mvc\Model\Manager::getRelationRecords` to correct using multi relation column [#12035](https://github.com/phalcon/cphalcon/issues/12035) diff --git a/phalcon/cache/backend/apc.zep b/phalcon/cache/backend/apc.zep index e1d84f0f7f5..9c8d494ff2d 100644 --- a/phalcon/cache/backend/apc.zep +++ b/phalcon/cache/backend/apc.zep @@ -85,6 +85,7 @@ class Apc extends Backend implements BackendInterface let lastKey = this->_lastKey; } else { let lastKey = "_PHCA" . this->_prefix . keyName; + let this->_lastKey = lastKey; } if !lastKey { diff --git a/phalcon/cache/backend/file.zep b/phalcon/cache/backend/file.zep index 99cd4f6d8fe..28e27e0c699 100644 --- a/phalcon/cache/backend/file.zep +++ b/phalcon/cache/backend/file.zep @@ -178,6 +178,7 @@ class File extends Backend implements BackendInterface let lastKey = this->_lastKey; } else { let lastKey = this->_prefix . this->getKey(keyName); + let this->_lastKey = lastKey; } if !lastKey { diff --git a/phalcon/cache/backend/libmemcached.zep b/phalcon/cache/backend/libmemcached.zep index 987aa7dadd7..5aff9ec2e95 100644 --- a/phalcon/cache/backend/libmemcached.zep +++ b/phalcon/cache/backend/libmemcached.zep @@ -185,6 +185,7 @@ class Libmemcached extends Backend implements BackendInterface let lastKey = this->_lastKey; } else { let lastKey = this->_prefix . keyName; + let this->_lastKey = lastKey; } if !lastKey { diff --git a/phalcon/cache/backend/memcache.zep b/phalcon/cache/backend/memcache.zep index fb7bcba8651..51ababcba4c 100644 --- a/phalcon/cache/backend/memcache.zep +++ b/phalcon/cache/backend/memcache.zep @@ -183,6 +183,7 @@ class Memcache extends Backend implements BackendInterface let lastKey = this->_lastKey; } else { let lastKey = this->_prefix . keyName; + let this->_lastKey = lastKey; } if !lastKey { diff --git a/phalcon/cache/backend/memory.zep b/phalcon/cache/backend/memory.zep index 11d12bcd9a7..1bcb45793fb 100644 --- a/phalcon/cache/backend/memory.zep +++ b/phalcon/cache/backend/memory.zep @@ -89,6 +89,7 @@ class Memory extends Backend implements BackendInterface, \Serializable let lastKey = this->_lastKey; } else { let lastKey = this->_prefix . keyName; + let this->_lastKey = lastKey; } if !lastKey { diff --git a/phalcon/cache/backend/mongo.zep b/phalcon/cache/backend/mongo.zep index 32a04682714..c88743e225a 100644 --- a/phalcon/cache/backend/mongo.zep +++ b/phalcon/cache/backend/mongo.zep @@ -114,74 +114,74 @@ class Mongo extends Backend implements BackendInterface throw new Exception("The backend requires a valid MongoDB connection string"); } - let mongo = new \MongoClient(server); - } - - /** - * Check if the database name is a string - */ - let database = options["db"]; - if !database || typeof database != "string" { - throw new Exception("The backend requires a valid MongoDB db"); - } - - /** - * Retrieve the connection name - */ - let collection = options["collection"]; - if !collection || typeof collection != "string" { - throw new Exception("The backend requires a valid MongoDB collection"); - } - - /** - * Make the connection and get the collection - */ - let mongoCollection = mongo->selectDb(database)->selectCollection(collection), - this->_collection = mongoCollection; - } - - return mongoCollection; - } - - /** - * Returns a cached content - */ - public function get(string keyName, int lifetime = null) -> var | null - { - var frontend, prefixedKey, conditions, document, cachedContent; - - let conditions = []; - let frontend = this->_frontend; - let prefixedKey = this->_prefix . keyName; - let this->_lastKey = prefixedKey; - - let conditions["key"] = prefixedKey; - let conditions["time"] = ["$gt": time()]; - - let document = this->_getCollection()->findOne(conditions); - if typeof document == "array" { - if fetch cachedContent, document["data"] { - if is_numeric(cachedContent) { - return cachedContent; - } - return frontend->afterRetrieve(cachedContent); - } else { - throw new Exception("The cache is corrupt"); - } - } - - return null; - } - - /** - * Stores cached content into the file backend and stops the frontend - * - * @param int|string keyName - * @param string content - * @param long lifetime - * @param boolean stopBuffer - */ - public function save(keyName = null, content = null, lifetime = null, boolean stopBuffer = true) -> boolean + let mongo = new \MongoClient(server); + } + + /** + * Check if the database name is a string + */ + let database = options["db"]; + if !database || typeof database != "string" { + throw new Exception("The backend requires a valid MongoDB db"); + } + + /** + * Retrieve the connection name + */ + let collection = options["collection"]; + if !collection || typeof collection != "string" { + throw new Exception("The backend requires a valid MongoDB collection"); + } + + /** + * Make the connection and get the collection + */ + let mongoCollection = mongo->selectDb(database)->selectCollection(collection), + this->_collection = mongoCollection; + } + + return mongoCollection; + } + + /** + * Returns a cached content + */ + public function get(string keyName, int lifetime = null) -> var | null + { + var frontend, prefixedKey, conditions, document, cachedContent; + + let conditions = []; + let frontend = this->_frontend; + let prefixedKey = this->_prefix . keyName; + let this->_lastKey = prefixedKey; + + let conditions["key"] = prefixedKey; + let conditions["time"] = ["$gt": time()]; + + let document = this->_getCollection()->findOne(conditions); + if typeof document == "array" { + if fetch cachedContent, document["data"] { + if is_numeric(cachedContent) { + return cachedContent; + } + return frontend->afterRetrieve(cachedContent); + } else { + throw new Exception("The cache is corrupt"); + } + } + + return null; + } + + /** + * Stores cached content into the file backend and stops the frontend + * + * @param int|string keyName + * @param string content + * @param long lifetime + * @param boolean stopBuffer + */ + public function save(keyName = null, content = null, lifetime = null, boolean stopBuffer = true) -> boolean { var lastkey, prefix, frontend, cachedContent, tmp, ttl, collection, timestamp, conditions, document, preparedContent, @@ -195,6 +195,7 @@ class Mongo extends Backend implements BackendInterface } else { let prefix = this->_prefix; let lastkey = prefix . keyName; + let this->_lastKey = lastkey; } if !lastkey { diff --git a/phalcon/cache/backend/redis.zep b/phalcon/cache/backend/redis.zep index dd286be5f23..a82dca136d6 100644 --- a/phalcon/cache/backend/redis.zep +++ b/phalcon/cache/backend/redis.zep @@ -189,6 +189,7 @@ class Redis extends Backend implements BackendInterface let prefix = this->_prefix; let prefixedKey = prefix . keyName; let lastKey = "_PHCR" . prefixedKey; + let this->_lastKey = lastKey; } if !lastKey { diff --git a/phalcon/cache/backend/xcache.zep b/phalcon/cache/backend/xcache.zep index f4adbd03b3d..790c9fdacd3 100644 --- a/phalcon/cache/backend/xcache.zep +++ b/phalcon/cache/backend/xcache.zep @@ -112,6 +112,7 @@ class Xcache extends Backend implements BackendInterface let lastKey = this->_lastKey; } else { let lastKey = "_PHCX" . this->_prefix . keyName; + let this->_lastKey = lastKey; } if !lastKey {