Skip to content

Store model queries in cache and refer back to them later.

Notifications You must be signed in to change notification settings

prgTW/CakePHP-Cacheable

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

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.

About

Store model queries in cache and refer back to them later.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published