Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all missing this->_lastKey update for backend cache #12072

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGELOG must be padded on the bottom

- 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)

Expand Down
1 change: 1 addition & 0 deletions phalcon/cache/backend/apc.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions phalcon/cache/backend/file.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions phalcon/cache/backend/libmemcached.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions phalcon/cache/backend/memcache.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions phalcon/cache/backend/memory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
137 changes: 69 additions & 68 deletions phalcon/cache/backend/mongo.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please return back tabs instead of spaces?

{
var lastkey, prefix, frontend, cachedContent, tmp, ttl,
collection, timestamp, conditions, document, preparedContent,
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions phalcon/cache/backend/redis.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions phalcon/cache/backend/xcache.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down