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])
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Méthodes publiques

Свойство Type Description
$trace boolean
$trackGet array
$trackGets integer
$trackSet array
$trackSets integer
$trackTime integer

Protected Properties

Свойство 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.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

public __construct ( )

activeCache() public static méthode

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
Résultat string shortname of current auto active cache

activeEnabled() public static méthode

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

activeStore() public static méthode

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

add() abstract public méthode

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
Résultat boolean true on success or false on failure.

addContainer() abstract public méthode

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.
Résultat boolean true on success or false on failure.

config() public méthode

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 méthode

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.
Résultat integer new value or false on failure.

exists() abstract public méthode

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

fail() public méthode

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 méthode

protected failure ( $Message )

fallback() protected méthode

protected fallback ( string $Key, array $Options ) : mixed
$Key string Cache key.
$Options array
Résultat mixed

flush() abstract public méthode

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
Résultat boolean true on success of false on failure.

get() abstract public méthode

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
Résultat mixed key value or false on failure or not found.

getPrefix() public méthode

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

getRevision() public méthode

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

hasFeature() public méthode

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

increment() abstract public méthode

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.
Résultat integer new value or false on failure.

incrementRevision() public méthode

public incrementRevision ( )

initialize() public static méthode

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

localClear() protected static méthode

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

localGet() protected méthode

protected localGet ( $key )

localSet() protected méthode

protected localSet ( $key, $value = null )

makeKey() public méthode

public makeKey ( $Key, $Options )

online() public méthode

Is the current cache available?
public online ( ) : boolean
Résultat boolean

option() public méthode

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 méthode

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 méthode

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
Résultat boolean true on success or false on failure.

replace() abstract public méthode

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
Résultat boolean true on success or false on failure.

store() abstract public méthode

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).
Résultat boolean true on success or false on failure.

stripKey() public méthode

public stripKey ( $Key, $Options )

trace() public static méthode

public static trace ( $trace = null )

type() public méthode

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

unregisterFeature() public méthode

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
Résultat boolean

$trackGet public_oe static_oe property

public static array $trackGet
Résultat array

$trackGets public_oe static_oe property

public static int $trackGets
Résultat integer

$trackSet public_oe static_oe property

public static array $trackSet
Résultat array

$trackSets public_oe static_oe property

public static int $trackSets
Résultat integer

$trackTime public_oe static_oe property

public static int $trackTime
Résultat integer