diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index f3a1eb024e..43f4e38a40 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -68,11 +68,13 @@ public function set($id, $data, array $tags = NULL, $lifetime) { } if ($this->exists($id)) { - $status = $this->db->update("caches", - array("tags" => $tags, "expiration" => $lifetime, "cache" => $data), array("key" => $id)); + $status = $this->db->update( + "caches", + array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), array("key" => $id)); } else { - $status = $this->db->insert("caches", - array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => $data)); + $status = $this->db->insert( + "caches", + array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data))); } return count($status) > 0; @@ -99,7 +101,7 @@ public function find($tag) { foreach ($db_result as $row) { // Add each cache to the array - $result[$row->id] = $row->cache; + $result[$row->key] = unserialize($row->cache); } // Turn notices back on @@ -131,7 +133,7 @@ public function get($id) { $ER = error_reporting(~E_NOTICE); // Return the valid cache data - $data = $cache->cache; + $data = unserialize($cache->cache); // Turn notices back on error_reporting($ER); diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index a5e0e7a0e1..6b525265b0 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -30,7 +30,7 @@ public function cache_exists_test() { $this->assert_false($this->_driver->exists("test_key"), "test_key should not be defined"); $id = md5(rand()); - $db->insert("caches", array("id" => $id, "tags" => ", ", + $db->insert("caches", array("key" => $id, "tags" => ", ", "expiration" => 84600 + time(), "cache" => serialize("some test data"))); @@ -41,7 +41,7 @@ public function cache_get_test() { $db = Database::instance(); $id = md5(rand()); - $db->insert("caches", array("id" => $id, "tags" => ", ", + $db->insert("caches", array("key" => $id, "tags" => ", ", "expiration" => 84600 + time(), "cache" => serialize("some test data")));