模块

Cache_Wincache
继承自 Cache

BootPHP Cache Wincache driver. Provides an opcode based driver for the BootPHP Cache library.

Configuration example

Below is an example of an wincache server configuration.

return array(
    'wincache' => array(                 // Driver group
           'driver'     => 'wincache',  // using wincache driver
     ),
)

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.

General cache group configuration settings

Below are the settings available to all types of cache driver.

Name Required Description
driver YES (string) The driver type to use

System requirements

  • 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
package
BootPHP/缓存
author
Tinsh
copyright
© 2005-2016 Kilofox Studio

该类在 MODPATH/cache/classes/cache/wincache.php 第 45 行声明。

常量

DEFAULT_EXPIRE

integer 3600

属性

public static string $default

default driver to use

string(4) "file"

public static BootPHP_Cache $instances

instances

array(0) 

protected Config $_config

方法

public delete( string $id ) (在 Cache_Wincache 中定义)

Delete a cache entry based on id

// Delete 'foo' entry from the wincache group
Cache::instance('wincache')->delete('foo');

参数

  • string $id required - Id to remove from cache

返回值

  • boolean

源代码

public function delete($id)
{
	return wincache_ucache_delete($this->_sanitize_id($id));
}

public deleteAll( ) (在 Cache_Wincache 中定义)

Delete all cache entries.

Beware of using this method when using shared memory cache systems, as it will wipe every entry within the system for all clients.

// Delete all cache entries in the wincache group
Cache::instance('wincache')->deleteAll();

返回值

  • boolean

源代码

public function deleteAll()
{
	return wincache_ucache_clear();
}

public get( string $id [, string $default = NULL ] ) (在 Cache_Wincache 中定义)

Retrieve a cached value entry by id.

// Retrieve cache entry from wincache group
$data = Cache::instance('wincache')->get('foo');

// Retrieve cache entry from wincache group and return 'bar' if miss
$data = Cache::instance('wincache')->get('foo', 'bar');

参数

  • string $id required - Id of cache to entry
  • string $default = NULL - Default value to return if cache miss

Tags

返回值

  • mixed

源代码

public function get($id, $default = NULL)
{
	$data = wincache_ucache_get($this->_sanitize_id($id), $success);
	return $success ? $data : $default;
}

public set( string $id , string $data [, integer $lifetime = NULL ] ) (在 Cache_Wincache 中定义)

Set a value to cache with id and lifetime

$data = 'bar';

// Set 'bar' to 'foo' in wincache group, using default expiry
Cache::instance('wincache')->set('foo', $data);

// Set 'bar' to 'foo' in wincache group for 30 seconds
Cache::instance('wincache')->set('foo', $data, 30);

参数

  • string $id required - Id of cache entry
  • string $data required - Data to set to cache
  • integer $lifetime = NULL - Lifetime in seconds

返回值

  • 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);
}

final public __clone( ) (在 Cache 中定义)

Overload the __clone() method to prevent cloning

Tags

返回值

  • void

源代码

final public function __clone()
{
	throw new Cache_Exception('Cloning of BootPHP_Cache objects is forbidden');
}

public config( [ mixed $key = NULL , mixed $value = NULL ] ) (在 Cache 中定义)

Getter and setter for the configuration. If no argument provided, the current configuration is returned. Otherwise the configuration is set to this class.

// Overwrite all configuration
$cache->config(array('driver' => 'memcache', '...'));

// Set a new configuration setting
$cache->config('servers', array(
    'foo' => 'bar',
    '...'
    ));

// Get a configuration setting
$servers = $cache->config('servers);

参数

  • mixed $key = NULL - Key to set to array, either array or config path
  • mixed $value = NULL - Value to associate with key

返回值

  • mixed

源代码

public function config($key = NULL, $value = NULL)
{
	if ($key === NULL)
		return $this->_config;
	if (is_array($key))
	{
		$this->_config = $key;
	}
	else
	{
		if ($value === NULL)
			return Arr::get($this->_config, $key);
		$this->_config[$key] = $value;
	}
	return $this;
}

public static instance( [ string $group = NULL ] ) (在 Cache 中定义)

Creates a singleton of a BootPHP Cache group. If no group is supplied the default cache group is used.

// Create an instance of the default group
$default_group = Cache::instance();

// Create an instance of a group
$foo_group = Cache::instance('foo');

// Access an instantiated group directly
$foo_group = Cache::$instances['default'];

参数

  • string $group = NULL - The name of the cache group to use [Optional]

Tags

返回值

  • BootPHP_Cache

源代码

public static function instance($group = NULL)
{
	// If there is no group supplied
	if ($group === NULL)
	{
		// Use the default setting
		$group = Cache::$default;
	}
	if (isset(Cache::$instances[$group]))
	{
		// Return the current group if initiated already
		return Cache::$instances[$group];
	}
	$config = BootPHP::$config->load('cache');
	if (!$config->offsetExists($group))
	{
		throw new Cache_Exception(
		'Failed to load BootPHP Cache group: :group', array(':group' => $group)
		);
	}
	$config = $config->get($group);
	// Create a new cache type instance
	$cache_class = 'Cache_' . ucfirst($config['driver']);
	Cache::$instances[$group] = new $cache_class($config);
	// Return the instance
	return Cache::$instances[$group];
}

protected __construct( array $config ) (在 Cache_Wincache 中定义)

Check for existence of the wincache extension This method cannot be invoked externally. The driver must be instantiated using the `Cache::instance()` method.

参数

  • array $config required - Configuration

Tags

源代码

protected function __construct(array $config)
{
	if (!extension_loaded('wincache'))
	{
		throw new Cache_Exception('PHP wincache extension is not available.');
	}
	parent::__construct($config);
}

protected _sanitize_id( string $id ) (在 Cache 中定义)

Replaces troublesome characters with underscores.

// Sanitize a cache id
$id = $this->_sanitize_id($id);

参数

  • string $id required - Id of cache to sanitize

返回值

  • string

源代码

protected function _sanitize_id($id)
{
	// Change slashes and spaces to underscores
	return str_replace(array('/', '\\', ' '), '_', $id);
}