sfPropelCacheableBehaviorPlugin - 1.1.0

A behavior and set of functions to cache Propel objects.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Dependencies Releases Changelog Contribute
Show source


A behavior and set of functions to cache Propel 1.2 objects (will not work with Propel 1.3). Requires sfCacheBackportPlugin.

The goal is to have an always up-to-date cache while writing a minimum ammount of code.

Basic configuration

Install sfCacheBackportPlugin.

Add in your app.yml (adapt it to your own usage): all: propel_behavior_cacheable: enabled: true classes: [ sfMemcacheCacheBackport ] options: prefix: object_cache lifetime: 3600 unique_instances: true

Note: you can change these classes and options settings for each classes, these are only default settings.

Simple (and shortest) example

In Penguin.php:

class Penguin
sfPropelBehavior::add('Penguin', array('cacheable'=>array()));

Or if you want to change an option: sfPropelBehavior::add('Penguin', array('cacheable'=>array('options'=>array('lifetime'=>86400))));

In PenguinPeer.php

class PenguinPeer:
  public static function retrieveByPK($pk, $con = null)

    return sfPropelCacheTools::cacheSingleResult(
      array(__CLASS__, 'retrieveByPKfromDB'),
      array($pk, $con)

  public static function retrieveByPKfromDB($pk, $con = null)

    return parent::retrieveByPK($pk, $con);

And that's it. Every retrieveByPK() is cached, and always up to date.

Other uses (detailled examples to come)

  • Cleaning up objects before caching
  • Storing related objects; clear the parent object when a related object is modified. (with the in_cacheable behavior)
  • Automatically setting and updating slug to ID entries
  • doSelectFromCache / doCachedCount
  • I18N handling (fetch all the related I18Ns before, set the current language after getting the object from the cache)
  • Disallowing an object to be cached or having a different lifetime by overloading the behavior's methods