PHP Class Gdn_Cache, vanilla

All cache objects should extend this to ensure a consistent public api for caching.
Since: 2.0.10
Author: Tim Gunter ([email protected])
ファイルを表示 Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$trace boolean
$trackGet array
$trackGets integer
$trackSet array
$trackSets integer
$trackTime integer

Protected Properties

Property Type Description
$cacheType Type of cache this this: one of CACHE_TYPE_MEMORY, CACHE_TYPE_FILE, CACHE_TYPE_NULL.
$containers List of cache containers.
$features List of features this cache system supports.
$localCache Local in-memory cache of fetched data. This prevents duplicate gets to memcache.
$stores Memory copy of store containers.

Public Methods

Method Description
__construct ( )
activeCache ( ) : string Gets the short name of the currently active cache.
activeEnabled ( type $ForceEnable = false ) : boolean Get the status of the active cache.
activeStore ( type $ForceMethod = null ) : mixed Returns the storage data for the active cache.
add ( string $Key, mixed $Value, array $Options = [] ) : boolean Add a value to the cache.
addContainer ( array $Options ) : boolean Add a container to the cache pool.
config ( $Key = null, $Default = null ) * Get the value of a store-specific config
decrement ( string $Key, integer $Amount = 1, $Options = [] ) : integer Decrement the value of the provided key by {@link $Amount}.
exists ( string $Key ) : array Check if a value exists in the cache.
fail ( string $server ) Register a temporary server connection failure.
flush ( ) : boolean Invalidate all items in the cache.
get ( string $Key, array $Options = [] ) : mixed Retrieve a key's value from the cache.
getPrefix ( $ForcePrefix = null, $WithRevision = true )
getRevision ( $ForcePrefix = null, $Force = false )
hasFeature ( integer $Feature ) : mixed Check whether this cache supports the specified feature.
increment ( string $Key, integer $Amount = 1, $Options = [] ) : integer Increment the value of the provided key by {@link $Amount}.
incrementRevision ( )
initialize ( $ForceEnable = false, $ForceMethod = false ) : Gdn_Cache Determines the currently installed cache solution and returns a fresh instance of its object.
makeKey ( $Key, $Options )
online ( ) : boolean Is the current cache available?
option ( $Option = null, $Default = null ) * Get the value of a store-specific option.
registerFeature ( integer $Feature, mixed $Meta = true ) Flag this cache as being capable of performing a feature.
remove ( string $Key, array $Options = [] ) : boolean Remove a key/value pair from the cache.
replace ( string $Key, mixed $Value, array $Options = [] ) : boolean Replace an existing key's value with the provided value.
store ( string $Key, mixed $Value, array $Options = [] ) : boolean Store a value in the cache.
stripKey ( $Key, $Options )
trace ( $trace = null )
type ( ) : string Returns a constant describing the type of cache implementation this object represents.
unregisterFeature ( integer $Feature ) Remove feature flag from this cache, for the specific feature.

Protected Methods

Method Description
failure ( $Message )
fallback ( string $Key, array $Options ) : mixed
localClear ( ) Clear local cache (process memory cache).
localGet ( $key )
localSet ( $key, $value = null )

Method Details

__construct() public method

public __construct ( )

activeCache() public static method

This method retrieves the name of the active cache according to the config file. It fires an event thereafter, allowing that value to be overridden by loaded plugins.
public static activeCache ( ) : string
return string shortname of current auto active cache

activeEnabled() public static method

Return whether or not the current cache method is enabled.
public static activeEnabled ( type $ForceEnable = false ) : boolean
$ForceEnable type
return boolean status of active cache

activeStore() public static method

For FileCache, the folder. For Memcache, the server(s).
public static activeStore ( type $ForceMethod = null ) : mixed
$ForceMethod type
return mixed Active Store Location

add() abstract public method

This fails if the item already exists in the cache.
abstract public add ( string $Key, mixed $Value, array $Options = [] ) : boolean
$Key string Cache key used for storage
$Value mixed Value to be cached
$Options array
return boolean true on success or false on failure.

addContainer() abstract public method

Add a container to the cache pool.
abstract public addContainer ( array $Options ) : boolean
$Options array An array of options with container constants as keys. - CONTAINER_LOCATION: required. the location of the container. SERVER:IP, Filepath, etc. - CONTAINER_PERSISTENT: optional (default true). whether to use connect() or pconnect() where applicable. - CONTAINER_WEIGHT: optional (default 1). number of buckets to create for this server which in turn control its probability of it being selected. - CONTAINER_RETRYINT: optional (default 15s). controls how often a failed container will be retried, the default value is 15 seconds. - CONTAINER_TIMEOUT: optional (default 1s). amount of time to wait for connection to container before timing out. - CONTAINER_CALLBACK: optional (default null). callback to execute if container fails to open/connect.
return boolean true on success or false on failure.

config() public method

The option keys are generic and cross-cache, but are always stored under $Configuration['Cache'][ActiveCacheName]['Config'][*].
public config ( $Key = null, $Default = null )
$Key The config key to retrieve

decrement() abstract public method

This will fail if the key does not already exist. Cannot take the value of $Key below 0.
abstract public decrement ( string $Key, integer $Amount = 1, $Options = [] ) : integer
$Key string Cache key used for storage.
$Amount integer Amount to shift value down.
return integer new value or false on failure.

exists() abstract public method

Check if a value exists in the cache.
abstract public exists ( string $Key ) : array
$Key string Cache key used for storage.
return array array(key => value) for existing key or false if not found.

fail() public method

This method will attempt to temporarily excise the offending server from the connect roster for a period of time.
public fail ( string $server )
$server string

failure() protected method

protected failure ( $Message )

fallback() protected method

protected fallback ( string $Key, array $Options ) : mixed
$Key string Cache key.
$Options array
return mixed

flush() abstract public method

Gdn_Cache::Flush() invalidates all existing cache items immediately. After invalidation none of the items will be returned in response to a retrieval command (unless it's stored again under the same key after Gdn_Cache::Flush() has invalidated the items).
abstract public flush ( ) : boolean
return boolean true on success of false on failure.

get() abstract public method

Retrieve a key's value from the cache.
abstract public get ( string $Key, array $Options = [] ) : mixed
$Key string Cache key used for storage.
$Options array
return mixed key value or false on failure or not found.

getPrefix() public method

public getPrefix ( $ForcePrefix = null, $WithRevision = true )

getRevision() public method

public getRevision ( $ForcePrefix = null, $Force = false )

hasFeature() public method

Check whether this cache supports the specified feature.
public hasFeature ( integer $Feature ) : mixed
$Feature integer One of the feature constants.
return mixed $Meta returns the meta data supplied during RegisterFeature().

increment() abstract public method

This will fail if the key does not already exist. Cannot take the value of $Key below 0.
abstract public increment ( string $Key, integer $Amount = 1, $Options = [] ) : integer
$Key string Cache key used for storage.
$Amount integer Amount to shift value up.
return integer new value or false on failure.

incrementRevision() public method

public incrementRevision ( )

initialize() public static method

Determines the currently installed cache solution and returns a fresh instance of its object.
public static initialize ( $ForceEnable = false, $ForceMethod = false ) : Gdn_Cache
return Gdn_Cache

localClear() protected static method

Clear local cache (process memory cache).
protected static localClear ( )

localGet() protected method

protected localGet ( $key )

localSet() protected method

protected localSet ( $key, $value = null )

makeKey() public method

public makeKey ( $Key, $Options )

online() public method

Is the current cache available?
public online ( ) : boolean
return boolean

option() public method

The option keys are specific to the active cache type, but are always stored under $Configuration['Cache'][ActiveCacheName]['Option'][*].
public option ( $Option = null, $Default = null )
$Option The option key to retrieve

registerFeature() public method

FEATURE_COMPRESS: this cache can compress and decompress values on the fly FEATURE_TIMEOUT: this cache can timeout while reading / writing FEATURE_EXPIRY: this cache can expire keys
public registerFeature ( integer $Feature, mixed $Meta = true )
$Feature integer One of the feature constants.
$Meta mixed An optional data to return when calling HasFeature. default true.

remove() abstract public method

Remove a key/value pair from the cache.
abstract public remove ( string $Key, array $Options = [] ) : boolean
$Key string Cache key used for storage.
$Options array
return boolean true on success or false on failure.

replace() abstract public method

This will fail if the provided key does not already exist.
abstract public replace ( string $Key, mixed $Value, array $Options = [] ) : boolean
$Key string Cache key used for storage.
$Value mixed Value to be cached.
$Options array
return boolean true on success or false on failure.

store() abstract public method

This works regardless of whether the item already exists in the cache.
abstract public store ( string $Key, mixed $Value, array $Options = [] ) : boolean
$Key string Cache key used for storage.
$Value mixed Value to be cached.
$Options array An array of cache feature constants. - FEATURE_COMPRESS: Allows items to be internally compressed/decompressed (bool). - FEATURE_EXPIRY: Allows items to autoexpire (seconds). - FEATURE_NOPREFIX: Allows disabling usage of key prefix (bool). - FEATURE_FORCEPREFIX: Allows forcing alternate key prefix (string). - FEATURE_FALLBACK: Allows querying DB for missing keys, or firing a callback (see Gdn_Cache->Fallback).
return boolean true on success or false on failure.

stripKey() public method

public stripKey ( $Key, $Options )

trace() public static method

public static trace ( $trace = null )

type() public method

Returns a constant describing the type of cache implementation this object represents.
public type ( ) : string
return string Type of cache. One of CACHE_TYPE_MEMORY, CACHE_TYPE_FILE, CACHE_TYPE_NULL

unregisterFeature() public method

Remove feature flag from this cache, for the specific feature.
public unregisterFeature ( integer $Feature )
$Feature integer One of the feature constants.

Property Details

$cacheType protected_oe property

Type of cache this this: one of CACHE_TYPE_MEMORY, CACHE_TYPE_FILE, CACHE_TYPE_NULL.
protected $cacheType

$containers protected_oe property

List of cache containers.
protected $containers

$features protected_oe property

List of features this cache system supports.
protected $features

$localCache protected_oe static_oe property

Local in-memory cache of fetched data. This prevents duplicate gets to memcache.
protected static $localCache

$stores protected_oe static_oe property

Memory copy of store containers.
protected static $stores

$trace public_oe static_oe property

public static bool $trace
return boolean

$trackGet public_oe static_oe property

public static array $trackGet
return array

$trackGets public_oe static_oe property

public static int $trackGets
return integer

$trackSet public_oe static_oe property

public static array $trackSet
return array

$trackSets public_oe static_oe property

public static int $trackSets
return integer

$trackTime public_oe static_oe property

public static int $trackTime
return integer