Interface \Scrivo\Cache

The Scrivo cache interface defines the interface for cache classes.

These cache classes can be used to hold Scrivo data in shared storage between requests and processes.

Defined in: Cache.php.


Constant summary

Name Description
CACHE_SLAM Constant to indicate that a value was not stored in the cache because the entry was already taken.
DATA_STORED Constant to indicate that a value was succesfully stored in the cache.
NO_SPACE Constant to indicate that a value was not stored in the cache because there was not enough storage available.

Method summary

Attr. Type Name / Description
public

delete($key)

Delete/remove a cache entry.

public object[]

entryList()

List all entries in the cache.

public mixed

fetch($key)

Retrieve a value from the cache.

public int

overwrite($key, $val, $ttl)

Store a variable in the cache, overwrite it if it already exists.

public int

store($key, $val, $ttl)

Store a variable in the cache.

 


Constants

CACHE_SLAM

Constant to indicate that a value was not stored in the cache because the entry was already taken.

Value: 2

DATA_STORED

Constant to indicate that a value was succesfully stored in the cache.

Value: 1

NO_SPACE

Constant to indicate that a value was not stored in the cache because there was not enough storage available.

Value: 3


Methods

public delete(\Scrivo\String $key)

Delete/remove a cache entry.

Parameters:

Type Name Def. Description
\Scrivo\String $key

A cache unique name for the key.

public object[] entryList()

List all entries in the cache.

This method returns an array in which the cache keys are the keys of the array entries and the data of each entry is an object of type stdClass that contains at least the following properties:

  • accessed: the access time
  • expires: the expiration time
  • created: the creation time
  • size: the size of the entry

Returns:

object[] List all entries in the cache.

public mixed fetch(\Scrivo\String $key)

Retrieve a value from the cache.

Parameters:

Type Name Def. Description
\Scrivo\String $key

The key for which to retrieve the value.

Returns:

mixed Retrieve a value from the cache.

public int overwrite(\Scrivo\String $key, mixed $val, int $ttl=3600)

Store a variable in the cache, overwrite it if it already exists.

Store any serializable variable in the cache. It is guaranteed that the data will be written. But note that it is not guaranteed that the next fetch will retrieve this value.

Parameters:

Type Name Def. Description
\Scrivo\String $key

A cache unique name for the key.

mixed $val

The (serializable) variabele to strore.

int $ttl 3600

Time to live in seconds.

Returns:

int Store a variable in the cache, overwrite it if it already exists.

Throws:

Exception Type Description
\Scrivo\SystemException When trying to store a NULL value.
public int store(\Scrivo\String $key, mixed $val, int $ttl=3600)

Store a variable in the cache.

Store any serializable variable in the cache. Note that it is not possible to overwrite an existing entry (cache slam). Such an event will not raise an error but the function will report it.

So subseqent calls to store should not made when the data to store changes between calls. If you activily want to store cache entries consider using overwrite() or first delete the entry before you store it.

Not to allow cache slams was a design decision because PHP does not allow thread save access to files. Thus when implementing a file cache disallowing a store request because an other thread is writing is considered expected behavoir.

Parameters:

Type Name Def. Description
\Scrivo\String $key

A cache unique name for the key.

mixed $val

The (serializable) variabele to strore.

int $ttl 3600

Time to live in seconds.

Returns:

int Store a variable in the cache.

Throws:

Exception Type Description
\Scrivo\SystemException When trying to store a NULL value.

Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013