apc.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: apc.php 7805 2008-10-30 17:30:26Z AD7six $ */
00003 /**
00004  * APC storage engine for cache.
00005  *
00006  *
00007  * PHP versions 4 and 5
00008  *
00009  * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
00010  * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
00011  *
00012  * Licensed under The MIT License
00013  * Redistributions of files must retain the above copyright notice.
00014  *
00015  * @filesource
00016  * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
00017  * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00018  * @package       cake
00019  * @subpackage    cake.cake.libs.cache
00020  * @since         CakePHP(tm) v 1.2.0.4933
00021  * @version       $Revision: 7805 $
00022  * @modifiedby    $LastChangedBy: AD7six $
00023  * @lastmodified  $Date: 2008-10-30 13:30:26 -0400 (Thu, 30 Oct 2008) $
00024  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
00025  */
00026 /**
00027  * APC storage engine for cache
00028  *
00029  * @package       cake
00030  * @subpackage    cake.cake.libs.cache
00031  */
00032 class ApcEngine extends CacheEngine {
00033 /**
00034  * Initialize the Cache Engine
00035  *
00036  * Called automatically by the cache frontend
00037  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
00038  *
00039  * @param array $setting array of setting for the engine
00040  * @return boolean True if the engine has been successfully initialized, false if not
00041  * @see CacheEngine::__defaults
00042  * @access public
00043  */
00044     function init($settings = array()) {
00045         parent::init(array_merge(array('engine' => 'Apc', 'prefix' => Inflector::slug(APP_DIR) . '_'), $settings));
00046         return function_exists('apc_cache_info');
00047     }
00048 /**
00049  * Write data for key into cache
00050  *
00051  * @param string $key Identifier for the data
00052  * @param mixed $value Data to be cached
00053  * @param integer $duration How long to cache the data, in seconds
00054  * @return boolean True if the data was succesfully cached, false on failure
00055  * @access public
00056  */
00057     function write($key, &$value, $duration) {
00058         $expires = time() + $duration;
00059         apc_store($key.'_expires', $expires, $duration);
00060         return apc_store($key, $value, $duration);
00061     }
00062 /**
00063  * Read a key from the cache
00064  *
00065  * @param string $key Identifier for the data
00066  * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
00067  * @access public
00068  */
00069     function read($key) {
00070         $time = time();
00071         $cachetime = intval(apc_fetch($key.'_expires'));
00072         if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
00073             return false;
00074         }
00075         return apc_fetch($key);
00076     }
00077 /**
00078  * Delete a key from the cache
00079  *
00080  * @param string $key Identifier for the data
00081  * @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
00082  * @access public
00083  */
00084     function delete($key) {
00085         return apc_delete($key);
00086     }
00087 /**
00088  * Delete all keys from the cache
00089  *
00090  * @return boolean True if the cache was succesfully cleared, false otherwise
00091  * @access public
00092  */
00093     function clear() {
00094         return apc_clear_cache('user');
00095     }
00096 }
00097 ?>

Generated on Sun Nov 22 00:30:52 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7