steerCMSCachedBehaviorPlugin

Steer CMS websites make heavy use of the Symfony caching system. It gives another layer of performance gain with relative ease, but the side effect is a rise in update complexity. What happens when a chached item is updated? The simple answer is deleting the cache, however to do this on a large application which might involve many data update points is neither convenient, nor is it DRY.

To make cache control easier, we implemented a behaviour which can be attached to Propel objects and automatically manage the relationship between data change and cache.

The steerCMSCachedBehaviorPlugin attaches a “cache contracts” record to propel objects. From this, automated flushing of the cache system can be achieved with less fuss, and no add-hoc code.

Adding the Behaviour

steerCMSCachedBehaviorPlugin can be used on any Propel object - just by adding the following code at the end of your base model class file.

For example:

sfPropelBehavior::add('steerCMSBlogPost', array('steerCMSCachedBehavior'));

Configuring the contracts is set into project.yml under the contracts section:

  #
# Cache Contracts
# ---------------
# ....
#
contracts:
steerCMSBlogInstance:
- "/frontend/*/template/*"
steerCMSBlogPost:
- "/frontend/*/template/*"
steerCMSCoreNodePublic:
- "/frontend/*/template/*"
steerCMSCalendarInstance:
- "/frontend/*/template/*"
steerCMSCalendarEvent:
- "/frontend/*/template/*"

Looking at the above example, we can see a fairly broad cache flush on the listed models - but you can be as granular as is needed. Multiple contracts can also be attached to a model - for example:

    steerCMSBlogPost:
- "/backend/*/template/*" // Delete backend templates
- "/frontend/*/template/*" // Delete frontend templates

Would clear both fontend and backend cache systems - but finer control can be achieved by the glob rules you specify in the project.yml file.