summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_cache_shared.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-06-09 11:07:46 +0200
committerAleksander Machniak <alec@alec.pl>2013-06-09 11:07:46 +0200
commit60b6d7c3894f61eb9c8bc40efe5528e91386bf94 (patch)
tree6f5572bc0722b6026e16ce3c3fc913f3757260ae /program/lib/Roundcube/rcube_cache_shared.php
parentd186405c0090772d1c26788dad9ea973f0421390 (diff)
Fix database cache expunge issues (#1489149) - added 'expires' column
Diffstat (limited to 'program/lib/Roundcube/rcube_cache_shared.php')
-rw-r--r--program/lib/Roundcube/rcube_cache_shared.php25
1 files changed, 19 insertions, 6 deletions
diff --git a/program/lib/Roundcube/rcube_cache_shared.php b/program/lib/Roundcube/rcube_cache_shared.php
index 2c4af2046..8f2574046 100644
--- a/program/lib/Roundcube/rcube_cache_shared.php
+++ b/program/lib/Roundcube/rcube_cache_shared.php
@@ -195,14 +195,25 @@ class rcube_cache_shared
$this->db->query(
"DELETE FROM " . $this->table
. " WHERE cache_key LIKE ?"
- . " AND " . $this->db->unixtimestamp('created') . " < ?",
- $this->prefix . '.%',
- time() - $this->ttl);
+ . " AND expires < " . $this->db->now(),
+ $this->prefix . '.%');
}
}
/**
+ * Remove expired records of all caches
+ */
+ static function gc()
+ {
+ $rcube = rcube::get_instance();
+ $db = $rcube->get_dbh();
+
+ $db->query("DELETE FROM " . $db->table_name('cache_shared') . " WHERE expires < " . $db->now());
+ }
+
+
+ /**
* Writes the cache back to the DB.
*/
function close()
@@ -328,7 +339,9 @@ class rcube_cache_shared
if ($key_exists) {
$result = $this->db->query(
"UPDATE " . $this->table .
- " SET created = " . $this->db->now() . ", data = ?" .
+ " SET created = " . $this->db->now() .
+ ", expires = " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL') .
+ ", data = ?".
" WHERE cache_key = ?",
$data, $key);
}
@@ -338,8 +351,8 @@ class rcube_cache_shared
// so, no need to check if record exist (see rcube_cache::read_record())
$result = $this->db->query(
"INSERT INTO ".$this->table.
- " (created, cache_key, data)".
- " VALUES (".$this->db->now().", ?, ?)",
+ " (created, expires, cache_key, data)".
+ " VALUES (".$this->db->now().", " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL') . ", ?, ?)",
$key, $data);
}