summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_cache.php
diff options
context:
space:
mode:
Diffstat (limited to 'program/lib/Roundcube/rcube_cache.php')
-rw-r--r--program/lib/Roundcube/rcube_cache.php45
1 files changed, 15 insertions, 30 deletions
diff --git a/program/lib/Roundcube/rcube_cache.php b/program/lib/Roundcube/rcube_cache.php
index a708cb292..deaba68e9 100644
--- a/program/lib/Roundcube/rcube_cache.php
+++ b/program/lib/Roundcube/rcube_cache.php
@@ -38,7 +38,6 @@ class rcube_cache
private $type;
private $userid;
private $prefix;
- private $table;
private $ttl;
private $packed;
private $index;
@@ -72,9 +71,8 @@ class rcube_cache
$this->db = function_exists('apc_exists'); // APC 3.1.4 required
}
else {
- $this->type = 'db';
- $this->db = $rcube->get_dbh();
- $this->table = $this->db->table_name('cache');
+ $this->type = 'db';
+ $this->db = $rcube->get_dbh();
}
// convert ttl string to seconds
@@ -194,31 +192,20 @@ class rcube_cache
*/
function expunge()
{
- if ($this->type == 'db' && $this->db && $this->ttl) {
+ if ($this->type == 'db' && $this->db) {
$this->db->query(
- "DELETE FROM ".$this->table.
+ "DELETE FROM ".$this->db->table_name('cache').
" WHERE user_id = ?".
" AND cache_key LIKE ?".
- " AND expires < " . $this->db->now(),
+ " AND " . $this->db->unixtimestamp('created')." < ?",
$this->userid,
- $this->prefix.'.%');
+ $this->prefix.'.%',
+ time() - $this->ttl);
}
}
/**
- * 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') . " WHERE expires < " . $db->now());
- }
-
-
- /**
* Writes the cache back to the DB.
*/
function close()
@@ -284,7 +271,7 @@ class rcube_cache
else {
$sql_result = $this->db->limitquery(
"SELECT data, cache_key".
- " FROM " . $this->table.
+ " FROM ".$this->db->table_name('cache').
" WHERE user_id = ?".
" AND cache_key = ?".
// for better performance we allow more records for one key
@@ -339,7 +326,7 @@ class rcube_cache
// Remove NULL rows (here we don't need to check if the record exist)
if ($data == 'N;') {
$this->db->query(
- "DELETE FROM " . $this->table.
+ "DELETE FROM ".$this->db->table_name('cache').
" WHERE user_id = ?".
" AND cache_key = ?",
$this->userid, $key);
@@ -350,10 +337,8 @@ class rcube_cache
// update existing cache record
if ($key_exists) {
$result = $this->db->query(
- "UPDATE " . $this->table.
- " SET created = " . $this->db->now().
- ", expires = " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL').
- ", data = ?".
+ "UPDATE ".$this->db->table_name('cache').
+ " SET created = ". $this->db->now().", data = ?".
" WHERE user_id = ?".
" AND cache_key = ?",
$data, $this->userid, $key);
@@ -363,9 +348,9 @@ class rcube_cache
// for better performance we allow more records for one key
// so, no need to check if record exist (see rcube_cache::read_record())
$result = $this->db->query(
- "INSERT INTO " . $this->table.
- " (created, expires, user_id, cache_key, data)".
- " VALUES (" . $this->db->now() . ", " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL') . ", ?, ?, ?)",
+ "INSERT INTO ".$this->db->table_name('cache').
+ " (created, user_id, cache_key, data)".
+ " VALUES (".$this->db->now().", ?, ?, ?)",
$this->userid, $key, $data);
}
@@ -426,7 +411,7 @@ class rcube_cache
}
$this->db->query(
- "DELETE FROM " . $this->table.
+ "DELETE FROM ".$this->db->table_name('cache').
" WHERE user_id = ?" . $where,
$this->userid);
}