diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/libraries/drivers/Cache/Database.php | 38 |
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; |