Class: AkCacheSweeper - X-Ref
Cache Sweepers need to be stored under:
AK_BASE_DIR/app/sweepers
Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change.
They do this by being half-observers, half-filters and implementing callbacks for both roles. A Sweeper example:
class ListSweeper extends AkCacheSweeper
{
var $observe = array("List", "Item");
function afterSave(&$record) {
$list = is_a($record,"List") ? $record : $record->list;
$this->expirePage(array("controller" => "lists", "action" => "public", "id" => $list->id));
$this->expireAction(array("controller" => "lists", "action" => "all"));
foreach($list->shares as $share) {
$this->expirePage(array("controller" => "lists", "action" => "show", "id" => $share->id));
}
}
}
The sweeper is assigned in the controllers that wish to have its job performed using the <tt>$cache_sweeper</tt> class attribute:
class ListsController extends ApplicationController {
var $caches_action = array("index", "show", "public", "feed");
var $cache_sweeper = array("list_sweeper" => array("only" => array("edit", "destroy", "share")));
....
}
In the example above, four actions are cached and three actions are responsible for expiring those caches.