[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Caching/ -> TAPCCache.php (source)

   1  <?php
   2  /**
   3   * TAPCCache class file
   4   *
   5   * @author Alban Hanry <compte_messagerie@hotmail.com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TAPCCache.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.Caching
  11   */
  12  
  13  /**
  14   * TAPCCache class
  15   *
  16   * TAPCCache implements a cache application module based on {@link http://www.php.net/apc APC}.
  17   *
  18   * By definition, cache does not ensure the existence of a value
  19   * even if it never expires. Cache is not meant to be an persistent storage.
  20   *
  21   * To use this module, the APC PHP extension must be loaded and set in the php.ini file the following:
  22   * <code>
  23   * apc.cache_by_default=0
  24   * </code>
  25   *
  26   * Some usage examples of TAPCCache are as follows,
  27   * <code>
  28   * $cache=new TAPCCache;  // TAPCCache may also be loaded as a Prado application module
  29   * $cache->init(null);
  30   * $cache->add('object',$object);
  31   * $object2=$cache->get('object');
  32   * </code>
  33   *
  34   * If loaded, TAPCCache will register itself with {@link TApplication} as the
  35   * cache module. It can be accessed via {@link TApplication::getCache()}.
  36   *
  37   * TAPCCache may be configured in application configuration file as follows
  38   * <code>
  39   * <module id="cache" class="System.Caching.TAPCCache" />
  40   * </code>
  41   *
  42   * @author Alban Hanry <compte_messagerie@hotmail.com>
  43   * @version $Id: TAPCCache.php 1397 2006-09-07 07:55:53Z wei $
  44   * @package System.Caching
  45   * @since 3.0b
  46   */
  47  class TAPCCache extends TCache
  48  {
  49     /**
  50      * Initializes this module.
  51      * This method is required by the IModule interface.
  52      * @param TXmlElement configuration for this module, can be null
  53      * @throws TConfigurationException if apc extension is not installed or not started, check your php.ini
  54      */
  55  	public function init($config)
  56      {
  57          if(!extension_loaded('apc'))
  58              throw new TConfigurationException('apccache_extension_required');
  59          parent::init($config);
  60      }
  61  
  62      /**
  63       * Retrieves a value from cache with a specified key.
  64       * This is the implementation of the method declared in the parent class.
  65       * @param string a unique key identifying the cached value
  66       * @return string the value stored in cache, false if the value is not in the cache or expired.
  67       */
  68  	protected function getValue($key)
  69      {
  70          return apc_fetch($key);
  71      }
  72  
  73      /**
  74       * Stores a value identified by a key in cache.
  75       * This is the implementation of the method declared in the parent class.
  76       *
  77       * @param string the key identifying the value to be cached
  78       * @param string the value to be cached
  79       * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
  80       * @return boolean true if the value is successfully stored into cache, false otherwise
  81       */
  82  	protected function setValue($key,$value,$expire)
  83      {
  84          return apc_store($key,$value,$expire);
  85      }
  86  
  87      /**
  88       * Stores a value identified by a key into cache if the cache does not contain this key.
  89       * This is the implementation of the method declared in the parent class.
  90       *
  91       * @param string the key identifying the value to be cached
  92       * @param string the value to be cached
  93       * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
  94       * @return boolean true if the value is successfully stored into cache, false otherwise
  95       */
  96  	protected function addValue($key,$value,$expire)
  97      {
  98          throw new TNotSupportedException('apccache_add_unsupported');
  99      }
 100  
 101      /**
 102       * Deletes a value with the specified key from cache
 103       * This is the implementation of the method declared in the parent class.
 104       * @param string the key of the value to be deleted
 105       * @return boolean if no error happens during deletion
 106       */
 107  	protected function deleteValue($key)
 108      {
 109          return apc_delete($key);
 110      }
 111  
 112      /**
 113       * Deletes all values from cache.
 114       * Be careful of performing this operation if the cache is shared by multiple applications.
 115       */
 116  	public function flush()
 117      {
 118          return apc_clear_cache('user');
 119      }
 120  }
 121  
 122  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7