Class QueryCacher

Handles caching queries and loading results from the cache.

Used by Cake\Datasource\QueryTrait internally.

Namespace: Cake\Datasource

Properties summary

  • $_config protected
    string|\Cake\Cache\CacheEngine

    Config for cache engine.

  • $_key protected
    string|callable

    The key or function to generate a key.

Method Summary

Method Detail

__construct() public

__construct(mixed $key, mixed $config)

Constructor.

Parameters

string|\Closure $key

The key or function to generate a key.

string|\Cake\Cache\CacheEngine $config

The cache config name or cache engine instance.

Throws

RuntimeException

_resolveCacher() protected

_resolveCacher()

Get the cache engine.

Returns

\Cake\Cache\CacheEngine

_resolveKey() protected

_resolveKey(mixed $query)

Get/generate the cache key.

Parameters

object $query

The query to generate a key for.

Returns

string

Throws

RuntimeException

fetch() public

fetch(mixed $query)

Load the cached results from the cache or run the query.

Parameters

object $query

The query the cache read is for.

Returns

\Cake\Datasource\ResultSetInterface|null

Either the cached results or null.

store() public

store(mixed $query, \Traversable $results)

Store the result set into the cache.

Parameters

object $query

The query the cache read is for.

\Traversable $results

The result set to store.

Returns

bool

True if the data was successfully cached, false on failure

Property Detail

$_config protected

Config for cache engine.

Type

string|\Cake\Cache\CacheEngine

$_key protected

The key or function to generate a key.

Type

string|callable

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Datasource.QueryCacher.html