| | |
| | | <?php |
| | | |
| | | /* |
| | | /** |
| | | +-----------------------------------------------------------------------+ |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2011, The Roundcube Dev Team | |
| | |
| | | | Author: Aleksander Machniak <alec@alec.pl> | |
| | | +-----------------------------------------------------------------------+ |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * Interface class for accessing Roundcube cache |
| | |
| | | $this->prefix = $prefix; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns cached value. |
| | | * |
| | |
| | | return $this->cache[$key]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Sets (add/update) value in cache. |
| | | * |
| | |
| | | $this->cache[$key] = $data; |
| | | $this->cache_changes[$key] = true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns cached value without storing it in internal memory. |
| | |
| | | return $this->read_record($key, true); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Sets (add/update) value in cache and immediately saves |
| | | * it in the backend, no internal memory will be used. |
| | |
| | | { |
| | | return $this->write_record($key, $this->serialize($data)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Clears the cache. |
| | |
| | | $this->remove_record($key, $prefix_mode); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Remove cache records older than ttl |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Remove expired records of all caches |
| | | */ |
| | |
| | | |
| | | $db->query("DELETE FROM " . $db->table_name('cache', true) . " WHERE `expires` < " . $db->now()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Writes the cache back to the DB. |
| | |
| | | if ($this->index_changed) { |
| | | $this->write_index(); |
| | | } |
| | | } |
| | | |
| | | // reset internal cache index, thanks to this we can force index reload |
| | | $this->index = null; |
| | | } |
| | | |
| | | /** |
| | | * Reads cache entry. |
| | |
| | | return $this->cache[$key]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Writes single cache record into DB. |
| | | * |
| | |
| | | return $this->db->affected_rows($result); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Deletes the cache record(s). |
| | | * |
| | |
| | | $this->userid); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Adds entry into memcache/apc DB. |
| | | * |
| | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Deletes entry from memcache/apc DB. |
| | | * |
| | |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Writes the index entry into memcache/apc DB. |
| | |
| | | $this->add_record($this->ikey(), $data); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Gets the index entry from memcache/apc DB. |
| | | */ |
| | |
| | | $this->index = $data ? unserialize($data) : array(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Creates per-user cache key name (for memcache and apc) |
| | | * |
| | |
| | | { |
| | | return sprintf('%d:%s:%s', $this->userid, $this->prefix, $key); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Creates per-user index cache key name (for memcache and apc) |