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 to store cache with
associated tags 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 push of Andrey Smirnoff's theoretical work
"Cache tagging with Memcached (in Russian)".
Some ideas are implemented in the real world (i.e. tag versions based on datetime
and microtime, cache hit/set logging, cache locking) and part of them are not
(atomic counter)

Create new file /config/factories.yml or edit each application's-level
/apps/%app%/config/factories.yml file

Cache tagging work for you each time when you save/update/delete Doctrine
record or fetch
them from DB.
So you should enable caching (sf_cache: true) in the all
applications you work with. I recommend you to create default factories.yml
for all applications you have by creating file /config/factories.yml (bellow will be this file content).
Symfony will check this file and load it as default factories.yml
configuration to all applications you have in the project.

This is /config/factories.yml content (you can copy&past this code into your
brand new created file) or merge this config with each application's
factories.yml (applications, where you need to data be fetched/written from/to cache)

all:
sfcachetaggingplugin:
template_lock: "lock_%s" # name for locks
template_tag: "tag_%s" # name for tags
microtime_precision: 5 # version precision (0, or positive number)
# (0 - without micro time, version will be 10 digits length)
# (5 - with micro time part, version will be 15 digits length)
lock_lifetime: 2 # seconds to keep lock, if failed to unlock after locking it

Using

Native use:

# Somewhere in the frontend, you need to print out latest posts
$posts = Doctrine::getTable('BlogPost')
->createQuery()
->orderBy('id DESC')
->limit(3)
->execute();
# write data to the cache ($posts is instance of the Doctrine_Collection_Cachetaggable)
$tagger->set('my_posts', $posts, 86400, $posts->getTags());
# fetch latest post to edit it
$post = posts->getFirst();
# prints something like "126070596212512"
print $post->getObjectVersion();
$post->setTitle('How to use sfCacheTaggingPlugin');
# save and update/upgrade version of the tag
$post->save();
# prints something like "126072290862231" (new version of the tag)
print $post->getObjectVersion();
# will return null
# $post object was updated, so, all $posts in cache "my_postsâ€ is invalidated automatically)
if ($data = $tagger->get('my_posts'))
{
# this block will not be executed
}
# save new data to the cache
$tagger->set('my_posts', $posts, null, $posts->getTags());
# will return data (objects are fresh)
if ($data = $tagger->get('my_posts'))
{
# this code block will be executed
}
$post = new BlogPost();
$post->setTitle('New post should be in inserted to the cache results');
$post->save();
# will return null, because 'my_posts' cache knows that it contains BlogPost objects
# and listens on new objects with same type that are newer
if ($data = $tagger->get('my_posts'))
{
# this block will not be executed
}
$posts = Doctrine::getTable('BlogPost')
->createQuery()
->orderBy('id DESC')
->limit(3)
->execute();
$tagger->set('my_posts', $posts, null, $posts->getTags());
# will return data
if ($data = $tagger->get('my_posts'))
{
# this block will be executed
}