Abstract Class Misago\ActionController\Caching


Cache store

The storage object is avaible throught cache.

You may use a particular storage (eg: file, redis, memcache) with cfg_set in your environment:

# config/environment.php
cfg_set('action_controller.cache_store', 'memcache'); 

See Misago\ActiveSupport\Cache for the list of available storages (defaults to Misago\ActiveSupport\Cache\MemoryStore).

Page caching

Caches the current action as a real file in the public directory, that matches the path of the current request. That way the web server will serve this generated page directly, without having to reach the framework.

Of course authentification and other filters cannot occur for these cached pages, since the application isn't even reached. If you need authentification check action caching below.

Please note that GET parameters are overlooked by page cache, which means that /members.rss and /members.rss?limit=10 will share the same cache file.


class PostsController extends Misago\ActionController\Base
  static function __constructStatic()
    static::caches_page('feed', array('unless' => array(':format' => 'html')));
  function create()
    $this->expire_page(array(':action' => 'index'));
  function index() {}
  function feed() {}


You may set conditions with if and unless options. Both accept any parameter that might be present in path parameters.

Action caching

In action caching, the request goes throught the Action Controller, but the action will not be processed if a cache is available. Filters will be processed thought, which allows to cache pages only available to authenticated users for instance.

The cache key is made from the host (and port), the path of the request and the GET parameters. Which means that x.domain.com/list, y.domain.com/list and x.domain.com/list?page=2 will be different caches. This allows for subdomains personalization for instance.


class PostsController extends Misago\ActionController\Base
  static function __constructStatic()
    static::caches_action('feed', array('unless' => array(':format' => 'html')));
  function __constructStatic()
     static::before_filter('authenticate' => array('only' => 'feed'));

TODO: :layout => false to only cache the view (while still rendering the layout). TODO: :cache_path TODO: :expires_in

Fragment caching [todo]

HTTP browser cache



Protected static attributes


Public static methods

caches_action($action, $options=array())

caches_page($action, $options=array())

Public instance methods

cache_page($content=null, $options=null)

Manually caches the current request as a real file into the public folder.


Deletes cached action.


Deletes a cached fragment.


Deletes a cached page.

expires_in($seconds, $options=array())

Sends a Cache-Control header for HTTP caching.

Defaults to private, telling proxies not to cache anything, which allows for some privacy of content.


expires_in('+1 hour', array('private' => false)) 


Sends a Cache-Control header with 'no-cache' to disallow or cancel HTTP caching of current request.