The sfCacheTaggingPlugin is a Symfony plugin, that helps to keep cached
content up-to-date without setting cache lifetime.
So-called "Smart caching", stores cache with fetched models tags and its versions.
Each time you save/update/delete objects, plugin increments object tag version and
all linked cache by specific tag name will automatically spoiled.

The sfCacheTaggingPlugin is a Symfony plugin, that helps to store cache with
associated tags and to keep cache content up-to-date based by incrementing tag
version when cache objects are edited/removed or new objects are ready to be a
part of cache content.

Developers

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release 1.0.1 - 18/12/2009

Release 1.0.0 - 16/12/2009

Release 0.1.0 - 16/12/2009

sfCacheTaggingPlugin

The sfCacheTaggingPlugin is a Symfony plugin, that helps to store cache with
associated tags and to keep cache content up-to-date based by incrementing tag
version when cache objects are edited/removed or new objects are ready to be a
part of cache content.

Description

This software was developed inspired by Andrey Smirnoff's theoretical work
"Cache tagging with Memcached (on Russian)".
Some ideas are implemented in the real world (e.g. tag versions based on datetime
and microtime, cache hit/set logging, cache locking) and part of them
are not (atomic counter).

Create a new file /config/factories.yml (common for all applications)
or edit application-level /apps/%application_name%/config/factories.yml file.

Often, if you have back-end for managing data and front-end to print them out
you should enable cache in both of them. That is because you edit/create/delete
records in back-end, so object tags should be updated to invalidate front-end cache.

I recommend you to create default factories.yml for all applications you have by
creating a file /config/factories.yml (you could find explained
and short working examples bellow).

Symfony will check for this file and will load it as a default factories.yml
configuration for all applications you have in the project.

This is /config/factories.yml content (you can copy&paste this code
into your brand new created file) or merge this config with each application
factories.yml file.

Restrictions: Backend's class should be inherited from sfCache
class. Then, it should be implement sfTaggingCacheInterface
(due a Doctrine cache engine compatibility).
Also, it should support the caching of objects and/or arrays.

YourModel:
tableName: your_model
actAs:
## CONFIGURATION SHORT VERSION
## Cachetaggable will detect your primary keys automatically
## and generates uniqueKeyFormat based on PK column count
## (e.g. '%s_%s' if table contains 2 primary keys)
Cachetaggable: ~
## CONFIGURATION EXPLAINED VERSION
#Cachetaggable:
# uniqueColumn: id # you can customize unique column name (default is all table primary keys)
# versionColumn: object_version # you can customize version column name (default is "object_version")
# uniqueKeyFormat: '%s' # you can customize key format (default is "%s")
#
# # if you have more then 1 unique column, you could pass all of them
# # as array (tag name will be based on all of them)
#
# uniqueColumn: [id, is_enabled]
# uniqueKeyFormat: '%d-%02b' # the order of unique columns
# # matches the "uniqueKeyFormat" template variables order

Adding tags to the whole page (action with layout)

Without a doubt, you have to enable the cache for that action in config/cache.yml:

showSuccess:
with_layout: true
enabled: true

Use it in your action to set the tags:

class carActions extends sfActions
{publicfunction executeShow (sfWebRequest $request){// get a "Cachetaggable" Doctrine_Record$car = Doctrine_Core::getTable('car')->find($request->getParameter('id'));
// set the tags for the action cache// See more about all available methods in PHPDOC of file// ./plugins/sfCacheTaggingPlugin/lib/util/sfViewCacheTagManagerBridge.class.php// $this->setPageTags($car->getTags());// or shorter$this->setPageTags($car);
$this->car = $car;
}}

Adding tags to the specific action (action without layout)

You have to disable "with_layout" and enable the cache for that action in config/cache.yml:

showSuccess:
with_layout: false
enabled: true

Action example

class carActions extends sfActions
{publicfunction executeShow (sfWebRequest $request){// get a "Cachetaggable" Doctrine_Record$car = Doctrine_Core::getTable('car')->find($request->getParameter('id'));
// set the tags for the action cache// See more about all available methods in PHPDOC of file// ./plugins/sfCacheTaggingPlugin/lib/util/sfViewCacheTagManagerBridge.class.php// $this->setActionTags($car->getTags());// or shorter$this->setActionTags($car);
$this->car = $car;
}}

Caching Doctrine_Records/Doctrine_Collections with its tags

To start caching objects/collection with its tags you have just to enable
result cache by calling Doctrine_Query::useResultCache():

class carActions extends sfActions
{// Somewhere in component/action, you need to print out latest posts$posts = Doctrine::getTable('BlogPost')
->createQuery()
->useResultCache()
->addWhere('lang = ?', 'en_GB')
->addWhere('is_visible = ?', true)
->limit(15)
->execute();
$this->posts = $posts;
// if you run this action again - you will pleasantly surprised// $posts now stored in cache and with object tags ;)// (object serialization powered by Doctrine build-in mechanism)// and expired as soon as you edit one of them// or add new record to table "blog_post"// when Doctrine_Query has many joins, tags will be fetched// recursively from all joined models}