summaryrefslogtreecommitdiff
path: root/modules/gallery/libraries/drivers
diff options
context:
space:
mode:
authorJoe7 <jozsef.rnagy@site.hu>2010-12-27 15:35:33 +0100
committerBharat Mediratta <bharat@menalto.com>2010-12-28 23:14:04 -0800
commit66fd8c7518ab71466aca72d20fb7bcd5f374af26 (patch)
treec467c3aa6faacb208235c84c259ae8d01d87761a /modules/gallery/libraries/drivers
parentfda92507964b9521b632a97c9e343b4639a657f7 (diff)
Using ON DUPLICATE KEY UPDATE instead of SELECT+UPDATE/INSERT style method (that does 2 trips to Database server and is less optimal).
exists() method is not needed anymore thus got removed
Diffstat (limited to 'modules/gallery/libraries/drivers')
-rw-r--r--modules/gallery/libraries/drivers/Cache/Database.php38
1 files changed, 8 insertions, 30 deletions
diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php
index 4f57b3da..7eda5b30 100644
--- a/modules/gallery/libraries/drivers/Cache/Database.php
+++ b/modules/gallery/libraries/drivers/Cache/Database.php
@@ -25,21 +25,6 @@ class Cache_Database_Driver extends Cache_Driver {
protected $db;
/**
- * Checks if a cache id is already set.
- *
- * @param string cache id
- * @return boolean
- */
- public function exists($id) {
- $count = db::build()
- ->where("key", "=", $id)
- ->where("expiration", ">=", time())
- ->limit("1")
- ->count_records("caches");
- return $count > 0;
- }
-
- /**
* Sets a cache item to the given data, tags, and lifetime.
*
* @param array assoc array of key => value pairs
@@ -60,22 +45,15 @@ class Cache_Database_Driver extends Cache_Driver {
$lifetime += time();
}
+ $db = Database::instance();
+ $tags = $db->escape($tags);
foreach ($items as $id => $data) {
- if ($this->exists($id)) {
- $status = db::build()
- ->update("caches")
- ->set("tags", $tags)
- ->set("expiration", $lifetime)
- ->set("cache", serialize($data))
- ->where("key", "=", $id)
- ->execute();
- } else {
- $status = db::build()
- ->insert("caches")
- ->columns("key", "tags", "expiration", "cache")
- ->values($id, $tags, $lifetime, serialize($data))
- ->execute();
- }
+ $id = $db->escape($id);
+ $data = $db->escape(serialize($data));
+ $db->query("INSERT INTO {caches} (`key`, `tags`, `expiration`, `cache`)
+ VALUES ('$id', '$tags', $lifetime, '$data')
+ ON DUPLICATE KEY UPDATE
+ `tags`=VALUES(tags), `expiration`=VALUES(expiration), `cache`=VALUES(cache)");
}
return true;