Skip to content

Commit

Permalink
Revert to serializing and deserializing data. The cache table can't
Browse files Browse the repository at this point in the history
accept PHP constructs like arrays (the tests were choking on this).

Update tests to reflect the new `key` column.
  • Loading branch information
bharat committed Jun 30, 2009
1 parent df17d57 commit 77a78b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions modules/gallery/libraries/drivers/Cache/Database.php
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/gallery/tests/Cache_Test.php
Expand Up @@ -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" => "<tag1>, <tag2>",
$db->insert("caches", array("key" => $id, "tags" => "<tag1>, <tag2>",
"expiration" => 84600 + time(),
"cache" => serialize("some test data")));

Expand All @@ -41,7 +41,7 @@ public function cache_get_test() {
$db = Database::instance();

$id = md5(rand());
$db->insert("caches", array("id" => $id, "tags" => "<tag1>, <tag2>",
$db->insert("caches", array("key" => $id, "tags" => "<tag1>, <tag2>",
"expiration" => 84600 + time(),
"cache" => serialize("some test data")));

Expand Down

0 comments on commit 77a78b4

Please sign in to comment.