Use it if you want to wrap model methods with cache

1.0.0 2014-02-07 14:59 UTC

This package is not auto-updated.

Last update: 2024-07-06 14:18:15 UTC


CakePHP Caching Behaviour

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

Caching Behaviour for CakePHP 2.1+

Use it if you want to wrap model methods with cache. For example you can use this for heavy model methods, that can't change output value for some time, but you need to invoke them very often.


cd my_cake_app/app
git clone git:// Plugin/Caching

or if you use git add as submodule:

cd my_cake_app
git submodule add "git://" "app/Plugin/Caching"

then add plugin loading in Config/bootstrap.php



Attach behaviour to model:

public $actsAs = array(
      'Caching.Caching' => array(
        'cache' => <valid cache config or name>, // optional
		'cachedObject' => <name of object class> // optional

If cache is not specified in config and method cache() used 'default' cache config. By default for 'cachedObject' used 'Caching.CachedObject' that stored in Lib folder. You can use your own class, that must be in Lib folder of app or plugin. But remember that your class must have same interface.


After attaching behavior to your model you can do (assuming your model has methods something() and somethingElse()):



$Model->cached(/*cache name*/)->something(/*args*/);


$CachedModel = $Model->cached(/*cache name or empty*/);

$Model->cached() returns object-wrapper that use magick methods and caching. So if expire date is ok, and you invoke same cached methods with same arguments and same cache config then model method calls only once.