PHP Class CacheSource

Author: Johannes Donath
Inheritance: extends Memcache
Mostrar archivo Open project: jeremyharris/cacher Class Usage Examples

Public Properties

Property Type Description
$source DataSource Stored original datasource for fallback methods

Public Methods

Method Description
__call ( string $name, array $arguments ) : mixed Redirects calls to original datasource methods. Needed if the Cacher.Cache behavior is attached before other behaviors that use the model's datasource methods.
__construct ( array $config = [] ) Constructor
clearModelCache ( Model $Model, $query = null ) * Clears the cache for a specific model and rewrites the map. Pass query to clear a specific query's cached results
describe ( mixed $model ) : mixed Since Datasource has the method describe(), it won't be caught __call().
read ( Model $Model, array $queryData = [], integer $recursive = null ) : array Reads from cache if it exists. If not, it falls back to the original datasource to retrieve the data and cache it for later

Protected Methods

Method Description
_key ( Model $Model, array $query ) : string Hashes a query into a unique string and creates a cache key
_map ( Model $Model, string $key ) Creates a cache map (used for deleting cache keys or groups)
_resetSource ( Model $Model ) : boolean Resets the model's datasource to the original

Method Details

__call() public method

Redirects calls to original datasource methods. Needed if the Cacher.Cache behavior is attached before other behaviors that use the model's datasource methods.
public __call ( string $name, array $arguments ) : mixed
$name string Original db source function name
$arguments array Arguments
return mixed

__construct() public method

Sets default options if none are passed when the datasource is created and creates the cache configuration. If a config is passed and is a valid Cache configuration, CacheSource uses its settings ### Extra config settings - original The name of the original datasource, i.e., 'default' (required) - config The name of the Cache configuration to use. Uses 'default' by default - other settings required by DataSource...
public __construct ( array $config = [] )
$config array Configure options

_key() protected method

Hashes a query into a unique string and creates a cache key
protected _key ( Model $Model, array $query ) : string
$Model Model The model
$query array The query
return string

_map() protected method

Creates a cache map (used for deleting cache keys or groups)
protected _map ( Model $Model, string $key )
$Model Model
$key string

_resetSource() protected method

Resets the model's datasource to the original
protected _resetSource ( Model $Model ) : boolean
$Model Model The model
return boolean

clearModelCache() public method

* Clears the cache for a specific model and rewrites the map. Pass query to clear a specific query's cached results
public clearModelCache ( Model $Model, $query = null )
$Model Model The model to clear the cache for
$query If null, clears all for this model

describe() public method

This ensures it is called on the original datasource properly.
public describe ( mixed $model ) : mixed
$model mixed
return mixed

read() public method

Reads from cache if it exists. If not, it falls back to the original datasource to retrieve the data and cache it for later
See also: DataSource::read()
public read ( Model $Model, array $queryData = [], integer $recursive = null ) : array
$Model Model
$queryData array
$recursive integer
return array Results

Property Details

$source public_oe property

Stored original datasource for fallback methods
public DataSource $source
return DataSource