| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* $Id: Cache.php,v 1.3 2008/12/26 02:43:09 slantview Exp $
|
| 4 |
*
|
| 5 |
* @file Cache.php
|
| 6 |
* Defines the base class for cache engines
|
| 7 |
*/
|
| 8 |
class Cache {
|
| 9 |
var $settings = array();
|
| 10 |
var $content = array();
|
| 11 |
var $prefix = '';
|
| 12 |
var $name = '';
|
| 13 |
var $lookup = '';
|
| 14 |
var $lock = '';
|
| 15 |
var $fast_cache = TRUE;
|
| 16 |
var $page_cache_fastpath = TRUE;
|
| 17 |
var $static = FALSE;
|
| 18 |
var $lifetime = 0;
|
| 19 |
|
| 20 |
function __construct($bin) {
|
| 21 |
global $conf;
|
| 22 |
|
| 23 |
$this->name = $bin;
|
| 24 |
|
| 25 |
// Setup our prefixes so that we can prefix a particular bin, or if not set use the default prefix.
|
| 26 |
if (isset($conf['cacherouter'][$bin]['prefix'])) {
|
| 27 |
$this->prefix = $conf['cacherouter'][$bin]['prefix'] .'-';
|
| 28 |
}
|
| 29 |
else if (isset($conf['cacherouter']['default']['prefix'])) {
|
| 30 |
$this->prefix = $conf['cacherouter']['default']['prefix'] .'-';
|
| 31 |
}
|
| 32 |
|
| 33 |
// This allows us to turn off fast_cache for cache_page so that we can get anonymous statistics.
|
| 34 |
if (isset($conf['cacherouter']['default']['fast_cache'])) {
|
| 35 |
$this->fast_cache = $conf['cacherouter']['default']['fast_cache'];
|
| 36 |
}
|
| 37 |
|
| 38 |
// This allows us to turn off static content caching for modules/bins that are already doing this.
|
| 39 |
if (isset($conf['cacherouter'][$bin]['static'])) {
|
| 40 |
$this->static = $conf['cacherouter'][$bin]['static'];
|
| 41 |
}
|
| 42 |
else if (isset($conf['cacherouter']['default']['static'])) {
|
| 43 |
$this->static = $conf['cacherouter']['default']['static'];
|
| 44 |
}
|
| 45 |
|
| 46 |
// Setup our prefixed lookup and lock table names for shared storage.
|
| 47 |
$this->lookup = $this->prefix . $this->name .'_lookup';
|
| 48 |
$this->lock = $this->prefix . $this->name .'_lock';
|
| 49 |
|
| 50 |
$this->lifetime = variable_get('cache_lifetime', 0);
|
| 51 |
}
|
| 52 |
|
| 53 |
function get($key) {
|
| 54 |
if (isset($this->content[$key]) && $this->static) {
|
| 55 |
return $this->content[$key];
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
function set($key, $value) {
|
| 60 |
if ($this->static) {
|
| 61 |
$this->content[$key] = $value;
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
function delete($key) {
|
| 66 |
if ($this->static) {
|
| 67 |
unset($this->content[$key]);
|
| 68 |
}
|
| 69 |
}
|
| 70 |
|
| 71 |
function flush() {
|
| 72 |
if ($this->static) {
|
| 73 |
$this->content = array();
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|
| 77 |
/**
|
| 78 |
* key()
|
| 79 |
* Get the full key of the item
|
| 80 |
*
|
| 81 |
* @param string $key
|
| 82 |
* The key to set.
|
| 83 |
* @return string
|
| 84 |
* Returns the full key of the cache item.
|
| 85 |
*/
|
| 86 |
function key($key) {
|
| 87 |
return urlencode($this->prefix . $this->name .'-'. $key);
|
| 88 |
}
|
| 89 |
}
|