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.

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 (in 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 or edit each application's level
/apps/%application_name%/config/factories.yml file

Cache tagging works for you each time you save/update/delete Doctrine record
or fetch them from DB. So you should enable caching (sf_cache: true) in
all applications you work with. I recommend you to create default factories.yml
for all applications you have by creating a file /config/factories.yml
(you could find working example bellow). Symfony will check this file and load
it as a default factories.yml configuration to 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's
factories.yml (applications, where you need the data to be fetched/written from/to cache)

Copy & past this content to yours /config/app.yml (project level or to each application's level /apps/%application_name%/config/app.yml)

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)
# (max precision value = 6, min = 0, only decimal numbers)
lock_lifetime: 2 # number of seconds to keep lock, if failed to unlock after locking it (default value if not set 2)
# value should be more then zero
tag_lifetime: 86400 # number of seconds to keep tags alive (default value if not set 86400)
# it is recommended to keep this value the same as you have declared in factories.yml at "all_view_cache_param_cache_param_lifetime" (86400)
# value should be more then zero
log_format_extended: 0 # logs will be stored in ``log/cache_%environment_name%.log``
# "0" print 1 char in one line
# "1" print 1 char, cache key, additional data (if available) per line
#
# Char explanation:
# "g": content cache not found
# "G": content cache is found
# "l": could not lock the content or the tag
# "L": content/tag was locked for writing
# "s": could not write new values to the cache (e.g. for lock reasons)
# "S": new values are saved to the cache
# "u": could not unlock the cache
# "U": cache was unlocked
# "t": cache tag was expired
# "T": cache tag is up-to-date
# "p": could not write new version of tag
# "P": tag version is updated
#
# Chars in lower case indicate negative operation
# Chars in upper case indicate positive operation

Using

Native use

not recommended - use Doctrine_Cache_* to store Doctrine_Record and Doctrine_Collection objects

# Somewhere in the frontend, you need to print out latest posts$posts = Doctrine::getTable('BlogPost')
->createQuery()
->orderBy('id DESC')
->limit(3)
->execute();
/* @var $tagger sfViewCacheTagManager */$tagger = $this->getContext()->getViewCacheManager();
# write data to the cache ($posts is instance of the Doctrine_Collection_Cachetaggable)$tagger->set('my_posts', $posts, 60 * 60 * 24 * 30/* 1 month */, $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 newerif($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 dataif($data = $tagger->get('my_posts')){# this block will be executed}