apc.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: apc_8php-source.html 580 2008-07-01 14:45:49Z gwoo $ */
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.
00011  *                              1785 E. Sahara Avenue, Suite 490-204
00012  *                              Las Vegas, Nevada 89104
00013  *
00014  * Licensed under The MIT License
00015  * Redistributions of files must retain the above copyright notice.
00016  *
00017  * @filesource
00018  * @copyright       Copyright 2005-2008, Cake Software Foundation, Inc.
00019  * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00020  * @package         cake
00021  * @subpackage      cake.cake.libs.cache
00022  * @since           CakePHP(tm) v 1.2.0.4933
00023  * @version         $Revision: 580 $
00024  * @modifiedby      $LastChangedBy: gwoo $
00025  * @lastmodified    $Date: 2008-07-01 09:45:49 -0500 (Tue, 01 Jul 2008) $
00026  * @license         http://www.opensource.org/licenses/mit-license.php The MIT License
00027  */
00028 /**
00029  * APC storage engine for cache
00030  *
00031  * @package     cake
00032  * @subpackage  cake.cake.libs.cache
00033  */
00034 class ApcEngine extends CacheEngine {
00035 /**
00036  * Initialize the Cache Engine
00037  *
00038  * Called automatically by the cache frontend
00039  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
00040  *
00041  * @param array $setting array of setting for the engine
00042  * @return boolean True if the engine has been successfully initialized, false if not
00043  * @see CacheEngine::__defaults
00044  * @access public
00045  */
00046     function init($settings = array()) {
00047         parent::init(array_merge(array('engine' => 'Apc', 'prefix' => Inflector::slug(APP_DIR) . '_'), $settings));
00048         return function_exists('apc_cache_info');
00049     }
00050 /**
00051  * Write data for key into cache
00052  *
00053  * @param string $key Identifier for the data
00054  * @param mixed $value Data to be cached
00055  * @param integer $duration How long to cache the data, in seconds
00056  * @return boolean True if the data was succesfully cached, false on failure
00057  * @access public
00058  */
00059     function write($key, &$value, $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         return apc_fetch($key);
00071     }
00072 /**
00073  * Delete a key from the cache
00074  *
00075  * @param string $key Identifier for the data
00076  * @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
00077  * @access public
00078  */
00079     function delete($key) {
00080         return apc_delete($key);
00081     }
00082 /**
00083  * Delete all keys from the cache
00084  *
00085  * @return boolean True if the cache was succesfully cleared, false otherwise
00086  * @access public
00087  */
00088     function clear() {
00089         return apc_clear_cache('user');
00090     }
00091 }
00092 ?>