PHP Class Jarves\Cache\Cacher

Afficher le fichier Open project: jarves/jarves Class Usage Examples

Protected Properties

Свойство Type Description
$distributedCache Jarves\Cache\Backend\AbstractCache
$fastCache Jarves\Cache\Backend\AbstractCache
$stopwatch Jarves\StopwatchHelper

Méthodes publiques

Méthode Description
__construct ( StopwatchHelper $stopwatch, AbstractCache $distributedCache, AbstractCache $fastCache )
deleteDistributedCache ( string $key ) Deletes a distributed cache
getDistributedCache ( string $key ) : mixed Returns a distributed cache value.
getFastCache ( string $key ) : mixed Returns a local cache value.
invalidateCache ( string $key, integer $time = null ) : boolean Marks a code as invalidate beginning at $time.
isCacheIsValid ( $key, $timestamp ) : integer | null Returns latest invalidation timestamp for the given $key.
setDistributedCache ( string $key, mixed $value, integer $lifeTime = null ) : boolean Sets a distributed cache.
setFastCache ( string $key, mixed $value, integer $lifeTime = null ) : boolean Sets a local cache using very fast cache techniques like apc_store or php arrays.

Method Details

__construct() public méthode

public __construct ( StopwatchHelper $stopwatch, AbstractCache $distributedCache, AbstractCache $fastCache )
$stopwatch Jarves\StopwatchHelper
$distributedCache Jarves\Cache\Backend\AbstractCache
$fastCache Jarves\Cache\Backend\AbstractCache

deleteDistributedCache() public méthode

Deletes a distributed cache
public deleteDistributedCache ( string $key )
$key string

getDistributedCache() public méthode

This uses cache invalidation mechanism described in
See also: setDistributedCache() for more information invalidateCache().
public getDistributedCache ( string $key ) : mixed
$key string
Résultat mixed null when not found

getFastCache() public méthode

Returns a local cache value.
public getFastCache ( string $key ) : mixed
$key string
Résultat mixed null when not found

invalidateCache() public méthode

This is the distributed cache controller. Use it if you want to invalidate caches on a distributed backend (setDistributedCache() and getDistributedCache()). You don't have to define the full key, instead you can pass only the starting part of the key. This means, if you have following caches defined: - news/list/2 - news/list/3 - news/list/4 - news/comments/134 - news/comments/51 you can mark all listing caches as invalid by calling - invalidateCache('news/list'); or mark all caches as invalid which starts with news/ you can call: - invalidateCache('news'); The invalidation mechanism explodes the key by / and checks all levels whether they're marked as invalid (through a microsecond timestamp) or not. Default is $time is mark all caches as invalid which are older than CURRENT. This method is called by the Jarves\Configuration\Event::$clearCaches configuration
public invalidateCache ( string $key, integer $time = null ) : boolean
$key string
$time integer Unix timestamp. Default is microtime(true). Uses float for ms.
Résultat boolean

isCacheIsValid() public méthode

Returns an timestamp as integer which tells the cache handler that all stored caches before this timestamp are automatically invalide. Returns null when no invalidation has set yet, means also that the cache with given key is valid.
public isCacheIsValid ( $key, $timestamp ) : integer | null
Résultat integer | null

setDistributedCache() public méthode

This stores a ms timestamp on the distributed cache (Jarves::setCache()) and the actual data on the high-speed cache driver (Jarves::setFastCache()). This mechanism makes sure, you gain the maximum performance by using the fast cache driver to store the actual data and using the distributed cache driver to store a ms timestamp where we can check (over several jarves.cms installations) whether the cache is still valid or not. Use Jarves::invalidateCache($key) to invalidate this cache. You don't have to define the full key, instead you can pass only a part of the key.
See also: invalidateCache for more information. Don't mix the usage of getDistributedCache() and getCache() since this method stores extra values at the value, which makes getCache() returning something invalid.
public setDistributedCache ( string $key, mixed $value, integer $lifeTime = null ) : boolean
$key string
$value mixed Only simple data types. Serialize your value if you have objects/arrays.
$lifeTime integer
Résultat boolean

setFastCache() public méthode

Does not use cache invalidation mechanism. Notes: Not practical for load balances or php-pm scenarios. Not even practical when you use PHP in PHP-FPM, because there are several php instances as well which do nothing know about cache refreshing in this fast cache. Is only useful for configuration purposes at bootstrap or in combination with the invalidation mechanism (which is then the same as if you would call setDistributedCache())
public setFastCache ( string $key, mixed $value, integer $lifeTime = null ) : boolean
$key string
$value mixed Only simple data types. Serialize your value if you have objects/arrays.
$lifeTime integer
Résultat boolean

Property Details

$distributedCache protected_oe property

protected AbstractCache,Jarves\Cache\Backend $distributedCache
Résultat Jarves\Cache\Backend\AbstractCache

$fastCache protected_oe property

protected AbstractCache,Jarves\Cache\Backend $fastCache
Résultat Jarves\Cache\Backend\AbstractCache

$stopwatch protected_oe property

protected StopwatchHelper,Jarves $stopwatch
Résultat Jarves\StopwatchHelper