Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 1.4 KB

README.md

File metadata and controls

34 lines (22 loc) · 1.4 KB

Cacheable Behavior

Cacheable is a wrapper method for standard queries. It stores each query result under a unique key based on the find type and parameters in the cache when performed. If the cached data already exists, it will use it instead of querying the database again.

Cache is automatically wiped out for a model during the afterSave and afterDelete of that model. You will have to manually clear the cache for deepfinds however.

Requires

You must have the clear_cache plugin by Ceeram installed in order for this to work.

Installation

App_Model or Model:

var $actsAs = array('Cacheable.Cacheable');

Basic Usage

To use, simply substitute any instance of Model->find() with Model->cache(). That's all there is to it.

$data = $this->Model->cache($type, [$queryOptions = array(), [$options = array()]])
  • $type: the type of Model->find() [first, all, list, custom, etc]
  • $queryOptions: the options to pass to the Model->find()
  • $options: the cache() specific options
    • duration: cache duration (default is '1 hour')
    • update: forces the cached data to refresh (default false)

Todo

  • Place deepfind cache into subfolders. When manually clearing the cache from a related model, this will allow only a subset of the cache to be cleared instead.