1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| Copyright (C) Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Caching engine - APC |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
/**
* Interface implementation class for accessing APC cache
*
* @package Framework
* @subpackage Cache
*/
class rcube_cache_apc extends rcube_cache
{
/**
* Indicates if APC module is enabled and in a required version
*
* @var bool
*/
protected $enabled;
public function __construct($userid, $prefix = '', $ttl = 0, $packed = true, $indexed = false)
{
parent::__construct($userid, $prefix, $ttl, $packed, $indexed);
$rcube = rcube::get_instance();
$this->type = 'apc';
$this->enabled = function_exists('apc_exists'); // APC 3.1.4 required
$this->debug = $rcube->config->get('apc_debug');
}
/**
* Remove cache records older than ttl
*/
public function expunge()
{
// No need for GC, entries are expunged automatically
}
/**
* Remove expired records of all caches
*/
public static function gc()
{
// No need for GC, entries are expunged automatically
}
/**
* Reads cache entry.
*
* @param string $key Cache internal key name
*
* @return mixed Cached value
*/
protected function get_item($key)
{
if (!$this->enabled) {
return false;
}
$data = apc_fetch($key);
if ($this->debug) {
$this->debug('get', $key, $data);
}
return $data;
}
/**
* Adds entry into memcache/apc/redis DB.
*
* @param string $key Cache internal key name
* @param mixed $data Serialized cache data
*
* @return bool True on success, False on failure
*/
protected function add_item($key, $data)
{
if (!$this->enabled) {
return false;
}
if (apc_exists($key)) {
apc_delete($key);
}
$result = apc_store($key, $data, $this->ttl);
if ($this->debug) {
$this->debug('set', $key, $data, $result);
}
return $result;
}
/**
* Deletes entry from memcache/apc/redis DB.
*
* @param string $key Cache internal key name
*
* @return bool True on success, False on failure
*/
protected function delete_item($key)
{
if (!$this->enabled) {
return false;
}
$result = apc_delete($key);
if ($this->debug) {
$this->debug('delete', $key, null, $result);
}
return $result;
}
}
|