2011-07-20 12:57:07 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
/**
|
|
|
|
* [Kohana Cache](api/Kohana_Cache) Wincache driver. Provides an opcode based
|
|
|
|
* driver for the Kohana Cache library.
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* ### Configuration example
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* Below is an example of an _wincache_ server configuration.
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* return array(
|
|
|
|
* 'wincache' => array( // Driver group
|
|
|
|
* 'driver' => 'wincache', // using wincache driver
|
|
|
|
* ),
|
|
|
|
* )
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* In cases where only one cache group is required, if the group is named `default` there is
|
|
|
|
* no need to pass the group name when instantiating a cache instance.
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* #### General cache group configuration settings
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* Below are the settings available to all types of cache driver.
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* Name | Required | Description
|
|
|
|
* -------------- | -------- | ---------------------------------------------------------------
|
|
|
|
* driver | __YES__ | (_string_) The driver type to use
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* ### System requirements
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* * Windows XP SP3 with IIS 5.1 and » FastCGI Extension
|
|
|
|
* * Windows Server 2003 with IIS 6.0 and » FastCGI Extension
|
|
|
|
* * Windows Vista SP1 with IIS 7.0 and FastCGI Module
|
|
|
|
* * Windows Server 2008 with IIS 7.0 and FastCGI Module
|
|
|
|
* * Windows 7 with IIS 7.5 and FastCGI Module
|
|
|
|
* * Windows Server 2008 R2 with IIS 7.5 and FastCGI Module
|
|
|
|
* * PHP 5.2.X, Non-thread-safe build
|
|
|
|
* * PHP 5.3 X86, Non-thread-safe VC9 build
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* @package Kohana/Cache
|
|
|
|
* @category Base
|
|
|
|
* @author Kohana Team
|
2013-04-13 06:17:56 +00:00
|
|
|
* @copyright (c) 2009-2012 Kohana Team
|
2011-07-20 12:57:07 +00:00
|
|
|
* @license http://kohanaphp.com/license
|
|
|
|
*/
|
|
|
|
class Kohana_Cache_Wincache extends Cache {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for existence of the wincache extension This method cannot be invoked externally. The driver must
|
|
|
|
* be instantiated using the `Cache::instance()` method.
|
|
|
|
*
|
2013-04-13 06:17:56 +00:00
|
|
|
* @param array $config configuration
|
|
|
|
* @throws Cache_Exception
|
2011-07-20 12:57:07 +00:00
|
|
|
*/
|
|
|
|
protected function __construct(array $config)
|
|
|
|
{
|
|
|
|
if ( ! extension_loaded('wincache'))
|
|
|
|
{
|
2013-04-13 06:17:56 +00:00
|
|
|
throw new Cache_Exception('PHP wincache extension is not available.');
|
2011-07-20 12:57:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a cached value entry by id.
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* // Retrieve cache entry from wincache group
|
|
|
|
* $data = Cache::instance('wincache')->get('foo');
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* // Retrieve cache entry from wincache group and return 'bar' if miss
|
|
|
|
* $data = Cache::instance('wincache')->get('foo', 'bar');
|
|
|
|
*
|
2013-04-13 06:17:56 +00:00
|
|
|
* @param string $id id of cache to entry
|
|
|
|
* @param string $default default value to return if cache miss
|
2011-07-20 12:57:07 +00:00
|
|
|
* @return mixed
|
2013-04-13 06:17:56 +00:00
|
|
|
* @throws Cache_Exception
|
2011-07-20 12:57:07 +00:00
|
|
|
*/
|
|
|
|
public function get($id, $default = NULL)
|
|
|
|
{
|
|
|
|
$data = wincache_ucache_get($this->_sanitize_id($id), $success);
|
|
|
|
|
|
|
|
return $success ? $data : $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a value to cache with id and lifetime
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* $data = 'bar';
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* // Set 'bar' to 'foo' in wincache group, using default expiry
|
|
|
|
* Cache::instance('wincache')->set('foo', $data);
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* // Set 'bar' to 'foo' in wincache group for 30 seconds
|
|
|
|
* Cache::instance('wincache')->set('foo', $data, 30);
|
|
|
|
*
|
2013-04-13 06:17:56 +00:00
|
|
|
* @param string $id id of cache entry
|
|
|
|
* @param string $data data to set to cache
|
|
|
|
* @param integer $lifetime lifetime in seconds
|
2011-07-20 12:57:07 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function set($id, $data, $lifetime = NULL)
|
|
|
|
{
|
|
|
|
if ($lifetime === NULL)
|
|
|
|
{
|
|
|
|
$lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return wincache_ucache_set($this->_sanitize_id($id), $data, $lifetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a cache entry based on id
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* // Delete 'foo' entry from the wincache group
|
|
|
|
* Cache::instance('wincache')->delete('foo');
|
|
|
|
*
|
2013-04-13 06:17:56 +00:00
|
|
|
* @param string $id id to remove from cache
|
2011-07-20 12:57:07 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function delete($id)
|
|
|
|
{
|
|
|
|
return wincache_ucache_delete($this->_sanitize_id($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all cache entries.
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* Beware of using this method when
|
|
|
|
* using shared memory cache systems, as it will wipe every
|
|
|
|
* entry within the system for all clients.
|
2013-04-13 06:17:56 +00:00
|
|
|
*
|
2011-07-20 12:57:07 +00:00
|
|
|
* // Delete all cache entries in the wincache group
|
|
|
|
* Cache::instance('wincache')->delete_all();
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function delete_all()
|
|
|
|
{
|
|
|
|
return wincache_ucache_clear();
|
|
|
|
}
|
|
|
|
}
|