Subversion-Projekte lars-tiefland.cakephp

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* SVN FILE: $Id: apc.php 7945 2008-12-19 02:16:01Z gwoo $ */
3
/**
4
 * APC storage engine for cache.
5
 *
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
10
 * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
11
 *
12
 * Licensed under The MIT License
13
 * Redistributions of files must retain the above copyright notice.
14
 *
15
 * @filesource
16
 * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
17
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
18
 * @package       cake
19
 * @subpackage    cake.cake.libs.cache
20
 * @since         CakePHP(tm) v 1.2.0.4933
21
 * @version       $Revision: 7945 $
22
 * @modifiedby    $LastChangedBy: gwoo $
23
 * @lastmodified  $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
24
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
25
 */
26
/**
27
 * APC storage engine for cache
28
 *
29
 * @package       cake
30
 * @subpackage    cake.cake.libs.cache
31
 */
32
class ApcEngine extends CacheEngine {
33
/**
34
 * Initialize the Cache Engine
35
 *
36
 * Called automatically by the cache frontend
37
 * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
38
 *
39
 * @param array $setting array of setting for the engine
40
 * @return boolean True if the engine has been successfully initialized, false if not
41
 * @see CacheEngine::__defaults
42
 * @access public
43
 */
44
	function init($settings = array()) {
45
		parent::init(array_merge(array('engine' => 'Apc', 'prefix' => Inflector::slug(APP_DIR) . '_'), $settings));
46
		return function_exists('apc_cache_info');
47
	}
48
/**
49
 * Write data for key into cache
50
 *
51
 * @param string $key Identifier for the data
52
 * @param mixed $value Data to be cached
53
 * @param integer $duration How long to cache the data, in seconds
54
 * @return boolean True if the data was succesfully cached, false on failure
55
 * @access public
56
 */
57
	function write($key, &$value, $duration) {
58
		$expires = time() + $duration;
59
		apc_store($key.'_expires', $expires, $duration);
60
		return apc_store($key, $value, $duration);
61
	}
62
/**
63
 * Read a key from the cache
64
 *
65
 * @param string $key Identifier for the data
66
 * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
67
 * @access public
68
 */
69
	function read($key) {
70
		$time = time();
71
		$cachetime = intval(apc_fetch($key.'_expires'));
72
		if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
73
			return false;
74
		}
75
		return apc_fetch($key);
76
	}
77
/**
78
 * Delete a key from the cache
79
 *
80
 * @param string $key Identifier for the data
81
 * @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
82
 * @access public
83
 */
84
	function delete($key) {
85
		return apc_delete($key);
86
	}
87
/**
88
 * Delete all keys from the cache
89
 *
90
 * @return boolean True if the cache was succesfully cleared, false otherwise
91
 * @access public
92
 */
93
	function clear() {
94
		return apc_clear_cache('user');
95
	}
96
}
97
?>