Login +

Cache / Advanced Caching

Introduction

With Sls 1.0.9, you can now configure full app cache (partial controller XML or complete HTML view).

We recommend you don't enabling cache on a developement server.

To recall, when cache is enabled, Sls don't list anymore recursivly all directories to update paths of ressources to load, so for example if you download a new plugin and you want to use it, it'll fail.

Also to minimize the cache management process by the developer, if cache is disabled, SillySmart will analyze all your select SQL queries to determine which controller part (static, component, controller or action) use which sql table.

So, during all your developement process, SillySmart will compose object/table dependencies to have a complete mapping of your application.

Unlike, when cache is enabled, SillySmart will only analyze your update/insert/delete SQL queries to know which object's cache have to be flush.

To summarize:

  • cache disabled > analyze SQL SELECT queries and build table/object mapping
  • cache enabled > analyze SQL UPDATE/INSERT/DELETE quieries and flush object's cache linked to the current table.

Configure cache

Cache can be:

  • public > same files cached for all users.
  • private > files cached files for each user based on php sessid.

You can cache full page (xHTML view) or partial controller side (static, component, action).

Full cache

If you want to cache an entire page, in SLS_Bo on Controllers & Actions, you can set the visibility, expiration time and scope "Full".

Sls will store a cached html file of the current page. It means that when user try to access this page, FrontController display directly the cached HTML file instead of executing whole MVC process ; btw Static, Component, Controller or action are not executed.

So, performance are greatly improved, no back-end handling is executed.

The cache will be flushed when expiration time reach or if an insert/update/delete sql query has been executed on the table linked to this action.

Partial cache

If you want to cache part of a page, in SLS_Bo on Controllers & Actions, you can set cache at several levels:

  • Static: you can set the visibility, expiration time.
  • Component: you can set the visibility, expiration time.
  • Action: you can set the visibility, expiration time and scope "Partial".

Sls will store a cached xml file of the current executed part. It means that when user try to access a page, GenericController will get XML cached instead of executing whole static, component or action.

So, performance are improved, no back-end handling is executed but XML/XSL parsing remains present.

The cache will be flushed when expiration time reach or if an insert/update/delete sql query has been executed on the table linked to this static, component, action.

Cache tree

Cache analyze current controller/action id and all GET/POST parameters to know if it need to get/set cached file.

Cached files are stored in "cache" node of projet.xml setting (default Public/Cache).

Arborescence:

  • Full
    • action: save HTML in Public/Cache/controller_id/action_id/[sessid/]querystring.html
  • Partial
    • action: save XML in Public/Cache/controller_id/action_id/[sessid/]querystring.xml
    • component: save XML in Public/Cache/component_name/controller_id/action_id/[sessid/]querystring.xml
    • static: save XML in Public/Cache/static_name/controller_id/action_id/[sessid/]querystring.xml

Cache flush

Sls automaticaly flush cache if expiration time is reach or if a table's datas have been modified (insert, update, delete).

You can flush cache at severals levels:

SLS_Bo

  • In Controllers & Actions, you can flush manually Static, Component, whole Controller or Action.
  • In Models, you can flush all controllers parts (Static, Component or Action) linked with a table.
  • In Production settings, you can flush whole app cache.

Code

You can access many flush methods:

  $this->_cache->flushStatic($staticName);
  $this->_cache->flushComponent($componentName);
  $this->_cache->flushController($controllerId);
  $this->_cache->flushAction($actionId);
  $this->_cache->flushUser($sessionId);
  $this->_cache->flushFromTable($tableName);

Related :