PHP Class Cachearium\CacheData

Show file Open project: corollarium/cachearium Class Usage Examples

Public Properties

Property Type Description
$data array The actual cached data
$dependencies array:CacheKey This is a storage of dependencies for this cache. This is stored here as the russian doll model will automatically push up dependencies. In the end this will probably be used by the storage for easy invalidation.
$key CacheKey
$lifetime integer Lifetime: how long this cache should live. It's up to the storage implementation the details of how this will be obeyed, if at all.

Public Methods

Method Description
__construct ( CacheKey $ck, $data = null )
addDependencies ( array $deps ) : CacheData Adds a dependency
addDependency ( CacheKey $k ) : CacheData Adds a dependency
appendCallback ( callable $callback ) : CacheData
appendData ( mixed $data ) : CacheData
appendRecursion ( CacheKey $k )
appendRecursionData ( CacheData $d )
checkClash ( CacheKey $k ) : boolean Checks if a set of keys clashes with the ones used here.
checkUpdateToDate ( CacheAbstract $cache ) : boolean Checks if dependencies are still fresh.
clearDependenciesHash ( )
dependencyInit ( CacheAbstract $cache, CacheKey $k ) : integer Init dependencies. If increment is not supported by backend return 0.
generateDependenciesHash ( CacheAbstract $cache ) : string Get a fresh hash based on dependencies. Does not update the current hash.
getDependencies ( )
getDependenciesHash ( )
getFirstData ( ) : any | null Convenience function. Returns the first data self::CACHEDATA_TYPE_DATA that you stored. Returns null if there is none.
getKey ( )
mergeDependencies ( CacheData $cd ) : CacheData
serialize ( ) : string Serialize this object to a string so we can easily store.
setDependencies ( array $deps, CacheAbstract $cache ) : CacheData Sets the list of dependencies and updates the dependency hash
setKey ( CacheKey $ck ) : CacheData
setLifetime ( integer $lifetime ) : CacheData
stringify ( CacheAbstract $c, $recurse = true ) Converts this data to a string that can output. This is not a hash key or a serialization, but an actual render for humans.
unserialize ( string $data ) : CacheData Unserializes data and returns a new CacheData. This is what you should use to get the object data from the storage.
updateDependenciesHash ( CacheAbstract $cache )
updateDependenciesHashIfNull ( CacheAbstract $cache )

Method Details

__construct() public method

public __construct ( CacheKey $ck, $data = null )
$ck CacheKey

addDependencies() public method

Adds a dependency
public addDependencies ( array $deps ) : CacheData
$deps array
return CacheData This

addDependency() public method

Adds a dependency
public addDependency ( CacheKey $k ) : CacheData
$k CacheKey
return CacheData This

appendCallback() public method

public appendCallback ( callable $callback ) : CacheData
$callback callable
return CacheData

appendData() public method

public appendData ( mixed $data ) : CacheData
$data mixed Any kind of data you want to store. usually strings.
return CacheData

appendRecursion() public method

public appendRecursion ( CacheKey $k )
$k CacheKey

appendRecursionData() public method

public appendRecursionData ( CacheData $d )
$d CacheData

checkClash() public method

Checks if a set of keys clashes with the ones used here.
public checkClash ( CacheKey $k ) : boolean
$k CacheKey
return boolean True if they match and there is a clash

checkUpdateToDate() public method

Checks if dependencies are still fresh.
public checkUpdateToDate ( CacheAbstract $cache ) : boolean
$cache CacheAbstract
return boolean

clearDependenciesHash() public method

dependencyInit() public method

Init dependencies. If increment is not supported by backend return 0.
public dependencyInit ( CacheAbstract $cache, CacheKey $k ) : integer
$cache CacheAbstract
$k CacheKey
return integer

generateDependenciesHash() public method

Get a fresh hash based on dependencies. Does not update the current hash.
public generateDependenciesHash ( CacheAbstract $cache ) : string
$cache CacheAbstract
return string

getDependencies() public method

public getDependencies ( )

getDependenciesHash() public method

public getDependenciesHash ( )

getFirstData() public method

Convenience function. Returns the first data self::CACHEDATA_TYPE_DATA that you stored. Returns null if there is none.
public getFirstData ( ) : any | null
return any | null

getKey() public method

public getKey ( )

mergeDependencies() public method

public mergeDependencies ( CacheData $cd ) : CacheData
$cd CacheData
return CacheData

serialize() public method

Serialize this object to a string so we can easily store.
public serialize ( ) : string
return string

setDependencies() public method

Sets the list of dependencies and updates the dependency hash
public setDependencies ( array $deps, CacheAbstract $cache ) : CacheData
$deps array
$cache CacheAbstract
return CacheData

setKey() public method

public setKey ( CacheKey $ck ) : CacheData
$ck CacheKey
return CacheData

setLifetime() public method

public setLifetime ( integer $lifetime ) : CacheData
$lifetime integer
return CacheData

stringify() public method

Converts this data to a string that can output. This is not a hash key or a serialization, but an actual render for humans.
public stringify ( CacheAbstract $c, $recurse = true )
$c CacheAbstract

unserialize() public static method

Unserializes data and returns a new CacheData. This is what you should use to get the object data from the storage.
public static unserialize ( string $data ) : CacheData
$data string
return CacheData

updateDependenciesHash() public method

public updateDependenciesHash ( CacheAbstract $cache )
$cache CacheAbstract

updateDependenciesHashIfNull() public method

public updateDependenciesHashIfNull ( CacheAbstract $cache )
$cache CacheAbstract

Property Details

$data public property

The actual cached data
public array $data
return array

$dependencies public property

This is a storage of dependencies for this cache. This is stored here as the russian doll model will automatically push up dependencies. In the end this will probably be used by the storage for easy invalidation.
public array:CacheKey $dependencies
return array:CacheKey

$key public property

public CacheKey,cachearium $key
return CacheKey

$lifetime public property

Lifetime: how long this cache should live. It's up to the storage implementation the details of how this will be obeyed, if at all.
public int $lifetime
return integer