Sledgehammer Framework

Cache extends Base
in package
implements ArrayAccess

A Cache node in the Caching graph.

Tags
link

API: return \Sledgehammer\cache('Twitter.feeds', '+15min', function () { // slow operation return $outcome; }); or Cache::rootNode()->Twitter->feeds->value(array('expires' => '15min'), function () { // slow operation return $outcome; });

todo

Implement dependancies (clearing a node should clear all childnodes, a expirationdate should not extend beyond the parents expirationdate)

Interfaces, Classes, Traits and Enums

ArrayAccess

Table of Contents

$_backend  : string
ENUM 'apc' or 'file'.
$_file  : resource|null
File handle for the file-backend.
$_guid  : string
Unique identifier for this cache node.
$_identifier  : string
Relative identifier for this app.
$_locked  : false|int
Timestamp of when lock took place or false if not locked.
$_nodes  : array<string|int, Cache>
Connected nodes.
$instance  : Cache
The app root node.
__call()  : mixed
Report that the $method doesn't exist.
__callStatic()  : mixed
Report that the $method doesn't exist.
__destruct()  : mixed
__get()  : Cache
Returns a related cache node.
__set()  : mixed
Report that $property doesn't exist and set the property to the given $value.
__sleep()  : mixed
__toString()  : string
The object is used as an string.
clear()  : mixed
Clear the cached value.
offsetExists()  : mixed
offsetGet()  : mixed
offsetSet()  : mixed
offsetUnset()  : mixed
rootNode()  : Cache
Return the rootnode for the app.
value()  : mixed
Returns the cached value when valid cache entry was found. otherwise retrieves the value via the $closure, stores it in the cache and returns it.
__construct()  : mixed
Constructor.
read()  : bool
Retrieve the value from the cache and set it to the $output value.
write()  : mixed
Store the value in the cache.
apcClear()  : mixed
Clear a cached valie.
apcLock()  : mixed
Obtain a lock for this cache entry.
apcRead()  : bool
Check if a key has a cached value, and set the value to the $output argument.
apcUnlock()  : mixed
Remove the lock for this cached entry.
apcWrite()  : mixed
Store the value in the cache.
fileCleanup()  : mixed
Cleanup expired cache entries.
fileClear()  : mixed
fileLock()  : mixed
fileRead()  : mixed
fileUnlock()  : mixed
fileWrite()  : mixed
lock()  : mixed
Obtain a lock for this cached node.
unlock()  : mixed
Release the lock for this cached node.

Properties

$_backend

ENUM 'apc' or 'file'.

private string $_backend

$_file

File handle for the file-backend.

private resource|null $_file

$_guid

Unique identifier for this cache node.

private string $_guid

$_identifier

Relative identifier for this app.

private string $_identifier

$_locked

Timestamp of when lock took place or false if not locked.

private false|int $_locked = false

$_nodes

Connected nodes.

private array<string|int, Cache> $_nodes = []

$instance

The app root node.

private static Cache $instance

Methods

__call()

Report that the $method doesn't exist.

public __call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__callStatic()

Report that the $method doesn't exist.

public static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__destruct()

public __destruct() : mixed
Return values
mixed

__get()

Returns a related cache node.

public __get(string $property) : Cache
Parameters
$property : string
Return values
Cache

__set()

Report that $property doesn't exist and set the property to the given $value.

public __set(string $property, mixed $value) : mixed
Parameters
$property : string
$value : mixed
Return values
mixed

__sleep()

public __sleep() : mixed
Return values
mixed

__toString()

The object is used as an string.

public __toString() : string
Return values
string

clear()

Clear the cached value.

public clear() : mixed
Return values
mixed

offsetExists()

public offsetExists(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

offsetGet()

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

offsetSet()

public offsetSet(mixed $offset, mixed $value) : mixed
Parameters
$offset : mixed
$value : mixed
Return values
mixed

offsetUnset()

public offsetUnset(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

rootNode()

Return the rootnode for the app.

public static rootNode() : Cache
Return values
Cache

value()

Returns the cached value when valid cache entry was found. otherwise retrieves the value via the $closure, stores it in the cache and returns it.

public value(string|int|array<string|int, mixed> $options, callable $closure) : mixed
Parameters
$options : string|int|array<string|int, mixed>

A string or int is interpreted as a 'expires' option. array( 'max_age' => int|string // The entry must be newer than the $maxAge. Example: "-5min", "2012-01-01" 'expires' => int|string, // A string is parsed via strtotime(). Examples: '+5min' or '2020-01-01' int's larger than 3600 (1 hour) are interpreted as unix timestamp expire date. And int's smaller or equal to 3600 are interpreted used as ttl. 'forever' => bool, // Default false (When true no ) 'lock' => (bool) // Default true, Prevents a cache stampede (http://en.wikipedia.org/wiki/Cache_stampede) )

$closure : callable

The method to retrieve/calculate the value.

Return values
mixed

__construct()

Constructor.

protected __construct(string $identifier, string $backend) : mixed
Parameters
$identifier : string
$backend : string

ENUM "apc" or "file"

Return values
mixed

read()

Retrieve the value from the cache and set it to the $output value.

protected read(array<string|int, mixed> &$output[, string|int|null $maxAge = false ]) : bool

Returns true if the cache entry was valid.

Parameters
$output : array<string|int, mixed>

The cached value

$maxAge : string|int|null = false

(optional) The entry must be newer than the $maxAge. Example: "-5min", "2012-01-01"

Return values
bool

write()

Store the value in the cache.

protected write(mixed $value[, string|int $expires = false ]) : mixed
Parameters
$value : mixed

The value

$expires : string|int = false

expires A string is parsed via strtotime(). Example $expires: '+5min' or '2020-01-01' int's larger than 3600 (1 hour) are interpreted as unix timestamp expire date. And int's smaller or equal to 3600 are interpreted used as ttl.

Return values
mixed

apcClear()

Clear a cached valie.

private apcClear() : mixed
Return values
mixed

apcLock()

Obtain a lock for this cache entry.

private apcLock() : mixed
Return values
mixed

apcRead()

Check if a key has a cached value, and set the value to the $output argument.

private apcRead(mixed &$output) : bool
Parameters
$output : mixed
Return values
bool

apcUnlock()

Remove the lock for this cached entry.

private apcUnlock() : mixed
Return values
mixed

apcWrite()

Store the value in the cache.

private apcWrite(mixed $value[, int $expires = null ]) : mixed
Parameters
$value : mixed
$expires : int = null
Return values
mixed

fileCleanup()

Cleanup expired cache entries.

private static fileCleanup() : mixed
Return values
mixed

fileClear()

private fileClear() : mixed
Return values
mixed

fileLock()

private fileLock() : mixed
Return values
mixed

fileRead()

private fileRead(mixed &$output) : mixed
Parameters
$output : mixed
Return values
mixed

fileUnlock()

private fileUnlock() : mixed
Return values
mixed

fileWrite()

private fileWrite(mixed $value[, mixed $expires = null ]) : mixed
Parameters
$value : mixed
$expires : mixed = null
Return values
mixed

lock()

Obtain a lock for this cached node.

private lock() : mixed
Return values
mixed

unlock()

Release the lock for this cached node.

private unlock() : mixed
Tags
throws
Exception
Return values
mixed

Search results