Source for file wincache.php

Documentation is available at wincache.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Cache
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * WINCACHE cache storage handler
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Cache
  17.  * @see         http://php.net/manual/en/book.wincache.php
  18.  * @since       11.1
  19.  */
  20. {
  21.     /**
  22.      * Constructor
  23.      *
  24.      * @param   array  $options  Optional parameters.
  25.      *
  26.      * @since   11.1
  27.      */
  28.     public function __construct($options array())
  29.     {
  30.         parent::__construct($options);
  31.     }
  32.  
  33.     /**
  34.      * Get cached data from WINCACHE by id and group
  35.      *
  36.      * @param   string   $id         The cache data id
  37.      * @param   string   $group      The cache data group
  38.      * @param   boolean  $checkTime  True to verify cache time expiration threshold
  39.      *
  40.      * @return  mixed  Boolean false on failure or a cached data string
  41.      *
  42.      * @since   11.1
  43.      */
  44.     public function get($id$group$checkTime true)
  45.     {
  46.         $cache_id $this->_getCacheId($id$group);
  47.         $cache_content wincache_ucache_get($cache_id);
  48.         return $cache_content;
  49.     }
  50.  
  51.     /**
  52.      * Get all cached data
  53.      *
  54.      * @return  array    data
  55.      *
  56.      * @since   11.1
  57.      */
  58.     public function getAll()
  59.     {
  60.         parent::getAll();
  61.  
  62.         $allinfo wincache_ucache_info();
  63.         $keys $allinfo['cache_entries'];
  64.         $secret $this->_hash;
  65.         $data array();
  66.  
  67.         foreach ($keys as $key)
  68.         {
  69.             $name $key['key_name'];
  70.             $namearr explode('-'$name);
  71.             if ($namearr !== false && $namearr[0== $secret && $namearr[1== 'cache')
  72.             {
  73.                 $group $namearr[2];
  74.                 if (!isset($data[$group]))
  75.                 {
  76.                     $item new JCacheStorageHelper($group);
  77.                 }
  78.                 else
  79.                 {
  80.                     $item $data[$group];
  81.                 }
  82.                 if (isset($key['value_size']))
  83.                 {
  84.                     $item->updateSize($key['value_size'1024);
  85.                 }
  86.                 else
  87.                 {
  88.                     // Dummy, WINCACHE version is too low.
  89.                     $item->updateSize(1);
  90.                 }
  91.                 $data[$group$item;
  92.             }
  93.         }
  94.  
  95.         return $data;
  96.     }
  97.  
  98.     /**
  99.      * Store the data to WINCACHE by id and group
  100.      *
  101.      * @param   string  $id     The cache data id
  102.      * @param   string  $group  The cache data group
  103.      * @param   string  $data   The data to store in cache
  104.      *
  105.      * @return  boolean  True on success, false otherwise
  106.      *
  107.      * @since   11.1
  108.      */
  109.     public function store($id$group$data)
  110.     {
  111.         $cache_id $this->_getCacheId($id$group);
  112.         return wincache_ucache_set($cache_id$data$this->_lifetime);
  113.     }
  114.  
  115.     /**
  116.      * Remove a cached data entry by id and group
  117.      *
  118.      * @param   string  $id     The cache data id
  119.      * @param   string  $group  The cache data group
  120.      *
  121.      * @return  boolean  True on success, false otherwise
  122.      *
  123.      * @since   11.1
  124.      */
  125.     public function remove($id$group)
  126.     {
  127.         $cache_id $this->_getCacheId($id$group);
  128.         return wincache_ucache_delete($cache_id);
  129.     }
  130.  
  131.     /**
  132.      * Clean cache for a group given a mode.
  133.      *
  134.      * @param   string  $group  The cache data group
  135.      * @param   string  $mode   The mode for cleaning cache [group|notgroup]
  136.      *  group mode    : cleans all cache in the group
  137.      *  notgroup mode : cleans all cache not in the group
  138.      *
  139.      * @return  boolean  True on success, false otherwise
  140.      *
  141.      * @since   11.1
  142.      */
  143.     public function clean($group$mode null)
  144.     {
  145.         $allinfo wincache_ucache_info();
  146.         $keys $allinfo['cache_entries'];
  147.         $secret $this->_hash;
  148.  
  149.         foreach ($keys as $key)
  150.         {
  151.             if (strpos($key['key_name']$secret '-cache-' $group '-'=== xor $mode != 'group')
  152.             {
  153.                 wincache_ucache_delete($key['key_name']);
  154.             }
  155.         }
  156.         return true;
  157.     }
  158.  
  159.     /**
  160.      * Force garbage collect expired cache data as items are removed only on get/add/delete/info etc
  161.      *
  162.      * @return  boolean  True on success, false otherwise.
  163.      *
  164.      * @since   11.1
  165.      */
  166.     public function gc()
  167.     {
  168.         $allinfo wincache_ucache_info();
  169.         $keys $allinfo['cache_entries'];
  170.         $secret $this->_hash;
  171.  
  172.         foreach ($keys as $key)
  173.         {
  174.             if (strpos($key['key_name']$secret '-cache-'))
  175.             {
  176.                 wincache_ucache_get($key['key_name']);
  177.             }
  178.         }
  179.     }
  180.  
  181.     /**
  182.      * Test to see if the cache storage is available.
  183.      *
  184.      * @return boolean  True on success, false otherwise.
  185.      *
  186.      * @since   12.1
  187.      */
  188.     public static function isSupported()
  189.     {
  190.         $test extension_loaded('wincache'&& function_exists('wincache_ucache_get'&& !strcmp(ini_get('wincache.ucenabled')'1');
  191.         return $test;
  192.     }
  193. }

Documentation generated on Tue, 19 Nov 2013 15:18:35 +0100 by phpDocumentor 1.4.3