Kohana Cache Wincache driver. Provides an opcode based
driver for the Kohana Cache library.
Below is an example of an wincache server configuration.
return array (
'wincache' => array (
'driver' => 'wincache' ,
),
)
|
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 settingslink to this
Below are the settings available to all types of cache driver.
Name |
Required |
Description |
driver |
YES |
(string) The driver type to use |
- 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
- Kohana/Cache
- category
- Base
- author
- Kohana Team
- copyright
- © 2009-2012 Kohana Team
- license
- http://kohanaphp.com/license
Class declared in MODPATH/cache/classes/cache/wincache.php on line 3.
public static string
$defaultlink to this
default driver to use
string(4) "file"
public static Kohana_Cache
$instanceslink to this
instances
array(0)
protected Config
$_configlink to this
Delete a cache entry based on id
Cache::instance( 'wincache' )-> delete ( 'foo' );
|
Parameters
-
string
$id
required - Id to remove from cache
Return Values
Source Code
public function delete ( $id )
{
return wincache_ucache_delete( $this ->_sanitize_id( $id ));
}
|
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.
Cache::instance( 'wincache' )->delete_all();
|
Return Values
Source Code
public function delete_all()
{
return wincache_ucache_clear();
}
|
public get( string $id [, string $default = NULL ] )
(defined in Kohana_Cache_Wincache)
link to this
Retrieve a cached value entry by id.
$data = Cache::instance( 'wincache' )->get( 'foo' );
$data = Cache::instance( 'wincache' )->get( 'foo' , 'bar' );
|
Parameters
-
string
$id
required - Id of cache to entry
-
string
$default
= NULL - Default value to return if cache miss
Tags
Return Values
Source Code
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 ] )
(defined in Kohana_Cache_Wincache)
link to this
Set a value to cache with id and lifetime
$data = 'bar' ;
Cache::instance( 'wincache' )->set( 'foo' , $data );
Cache::instance( 'wincache' )->set( 'foo' , $data , 30);
|
Parameters
-
string
$id
required - Id of cache entry
-
string
$data
required - Data to set to cache
-
integer
$lifetime
= NULL - Lifetime in seconds
Return Values
Source Code
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 );
}
|
Overload the __clone() method to prevent cloning
Tags
Return Values
Source Code
final public function __clone()
{
throw new Cache_Exception( 'Cloning of Kohana_Cache objects is forbidden' );
}
|
public config( [ mixed $key = NULL , mixed $value = NULL ] )
(defined in Kohana_Cache)
link to this
Getter and setter for the configuration. If no argument provided, the
current configuration is returned. Otherwise the configuration is set
to this class.
$cache ->config( array ( 'driver' => 'memcache' , '...' ));
$cache ->config( 'servers' , array (
'foo' => 'bar' ,
'...'
));
$servers = $cache ->config('servers);
|
Parameters
-
mixed
$key
= NULL - Key to set to array, either array or config path
-
mixed
$value
= NULL - Value to associate with key
Return Values
Source Code
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 ] )
(defined in Kohana_Cache)
link to this
Creates a singleton of a Kohana Cache group. If no group is supplied
the default cache group is used.
$default_group = Cache::instance();
$foo_group = Cache::instance( 'foo' );
$foo_group = Cache:: $instances [ 'default' ];
|
Parameters
-
string
$group
= NULL - The name of the cache group to use [Optional]
Tags
Return Values
Source Code
public static function instance( $group = NULL)
{
if ( $group === NULL)
{
$group = Cache:: $default ;
}
if (isset(Cache:: $instances [ $group ]))
{
return Cache:: $instances [ $group ];
}
$config = Kohana:: $config ->load( 'cache' );
if ( ! $config ->offsetExists( $group ))
{
throw new Cache_Exception(
'Failed to load Kohana Cache group: :group' ,
array ( ':group' => $group )
);
}
$config = $config ->get( $group );
$cache_class = 'Cache_' .ucfirst( $config [ 'driver' ]);
Cache:: $instances [ $group ] = new $cache_class ( $config );
return Cache:: $instances [ $group ];
}
|
Check for existence of the wincache extension This method cannot be invoked externally. The driver must
be instantiated using the Cache::instance()
method.
Parameters
-
array
$config
required - Configuration
Tags
Source Code
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 )
(defined in Kohana_Cache)
link to this
Replaces troublesome characters with underscores.
$id = $this ->_sanitize_id( $id );
|
Parameters
-
string
$id
required - Id of cache to sanitize
Return Values
Source Code
protected function _sanitize_id( $id )
{
return str_replace ( array ( '/' , '\\' , ' ' ), '_' , $id );
}
|