Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Source code for file /joomla/cache/storage/apc.php

Documentation is available at apc.php

  1. <?php
  2. /**
  3.  * @version        $Id: apc.php 9764 2007-12-30 07:48:11Z ircmaxell $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Cache
  6.  * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant
  9.  *  to the GNU General Public License, and as distributed it includes or
  10.  *  is derivative of works licensed under the GNU General Public License or
  11.  *  other free or open source software licenses.
  12.  *  See COPYRIGHT.php for copyright notices and details.
  13.  */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * APC cache storage handler
  20.  *
  21.  * @author        Louis Landry <louis.landry@joomla.org>
  22.  * @package        Joomla.Framework
  23.  * @subpackage    Cache
  24.  * @since        1.5
  25.  */
  26. {
  27.     /**
  28.      * Constructor
  29.      *
  30.      * @access protected
  31.      * @param array $options optional parameters
  32.      */
  33.     function __construct$options array() )
  34.     {
  35.         parent::__construct($options);
  36.  
  37.         $config            =JFactory::getConfig();
  38.         $this->_hash    $config->getValue('config.secret');
  39.     }
  40.  
  41.     /**
  42.      * Get cached data from APC by id and group
  43.      *
  44.      * @access    public
  45.      * @param    string    $id            The cache data id
  46.      * @param    string    $group        The cache data group
  47.      * @param    boolean    $checkTime    True to verify cache time expiration threshold
  48.      * @return    mixed    Boolean false on failure or a cached data string
  49.      * @since    1.5
  50.      */
  51.     function get($id$group$checkTime)
  52.     {
  53.         $cache_id $this->_getCacheId($id$group);
  54.         $this->_setExpire($cache_id);
  55.         return apc_fetch($cache_id);
  56.     }
  57.  
  58.     /**
  59.      * Store the data to APC by id and group
  60.      *
  61.      * @access    public
  62.      * @param    string    $id        The cache data id
  63.      * @param    string    $group    The cache data group
  64.      * @param    string    $data    The data to store in cache
  65.      * @return    boolean    True on success, false otherwise
  66.      * @since    1.5
  67.      */
  68.     function store($id$group$data)
  69.     {
  70.         $cache_id $this->_getCacheId($id$group);
  71.         apc_store($cache_id.'_expire'time());
  72.         return apc_store($cache_id$data$this->_lifetime);
  73.     }
  74.  
  75.     /**
  76.      * Remove a cached data entry by id and group
  77.      *
  78.      * @access    public
  79.      * @param    string    $id        The cache data id
  80.      * @param    string    $group    The cache data group
  81.      * @return    boolean    True on success, false otherwise
  82.      * @since    1.5
  83.      */
  84.     function remove($id$group)
  85.     {
  86.         $cache_id $this->_getCacheId($id$group);
  87.         apc_delete($cache_id.'_expire');
  88.         return apc_delete($cache_id);
  89.     }
  90.  
  91.     /**
  92.      * Clean cache for a group given a mode.
  93.      *
  94.      * group mode        : cleans all cache in the group
  95.      * notgroup mode    : cleans all cache not in the group
  96.      *
  97.      * @access    public
  98.      * @param    string    $group    The cache data group
  99.      * @param    string    $mode    The mode for cleaning cache [group|notgroup]
  100.      * @return    boolean    True on success, false otherwise
  101.      * @since    1.5
  102.      */
  103.     function clean($group$mode)
  104.     {
  105.         return true;
  106.     }
  107.  
  108.     /**
  109.      * Test to see if the cache storage is available.
  110.      *
  111.      * @static
  112.      * @access public
  113.      * @return boolean  True on success, false otherwise.
  114.      */
  115.     function test()
  116.     {
  117.         return extension_loaded('apc');
  118.     }
  119.  
  120.     /**
  121.      * Set expire time on each call since memcache sets it on cache creation.
  122.      *
  123.      * @access private
  124.      *
  125.      * @param string  $key   Cache key to expire.
  126.      * @param integer $lifetime  Lifetime of the data in seconds.
  127.      */
  128.     function _setExpire($key)
  129.     {
  130.         $lifetime    $this->_lifetime;
  131.         $expire        apc_fetch($key.'_expire');
  132.  
  133.         // set prune period
  134.         if ($expire $lifetime time()) {
  135.             apc_delete($key);
  136.             apc_delete($key.'_expire');
  137.         else {
  138.             apc_store($key.'_expire',  time());
  139.         }
  140.     }
  141.  
  142.     /**
  143.      * Get a cache_id string from an id/group pair
  144.      *
  145.      * @access    private
  146.      * @param    string    $id        The cache data id
  147.      * @param    string    $group    The cache data group
  148.      * @return    string    The cache_id string
  149.      * @since    1.5
  150.      */
  151.     function _getCacheId($id$group)
  152.     {
  153.         $name    md5($this->_application.'-'.$id.'-'.$this->_hash.'-'.$this->_language);
  154.         return 'cache_'.$group.'-'.$name;
  155.     }
  156. }

Documentation generated on Tue, 29 Jan 2008 18:44:09 +0000 by phpDocumentor 1.3.1