Invalidates a cached item when any of the Model dependencies you have specified have been updated since that cached item was created.
Example: if you list Model Post and Model Comment as dependancies for an item to cache then any update to either Post or Comment will invalidate that cache item.
Yii 1.1 or above
- git clone git@github.com:evan108108/CacheYii.git
- Place CacheYii in your 'protected/extensions' directory
- In your protected/config/main.php
'import'=>array( ... 'ext.CacheYii.*', ),
- Add this behavor to any model you intend to use as a cache dependency
function behaviors() { 'updateCacheMapBehavior' => array( 'class'=>'ext.CacheYii.EUpdateCacheMapBehavior', 'cacheExp'=>0, //This is optional and the default is 0 (0 means never expire) 'modelName'=>__CLASS__, //This is optional as it will assume current model ), }
$model = EDCache::get("YOUR_UNIQUE_ID_HERE", array("Post", "Comments")); if($model===false) { $model = Post::model()->with('comments')->findAll(); EDCache::set("YOUR_UNIQUE_ID_HERE", $model, 3600); }
$models = EDCache::gas("YOUR_UNIQUE_ID_HERE", array("Post", "Comments"), 3600, function() use ($model) { return $model->findAll(); });
EDCache::delete("YOUR_UNIQUE_ID_HERE");
EDCache::get(YOUR_UNIQUE_ID, ARRAY_OF_MODEL_DEPENDENCIES); EDCache::set(YOUR_UNIQUE_ID, DATA_TO_BE_CACHED, CACHE_EXPIRATION_IN_SECONDS);
Be the first person to leave a comment
Please login to leave your comment.