views:

147

answers:

3

I'd like to know if there is any distributed cache systems like memcached, velocity or sharedcache that allows me to tag content with more than just it's name, or that can relate items to eachother, so if i invalidate the cache for one item it also invalidates the related items too.

eg. if i have two pages that reference the same data and that data changes, i'd like the cache for the two referencing pages to invalidate.

  • or is this an addition to one of those projects begging to be developed? :)

edit: i'm on asp.net

+2  A: 

I believe that deletion of dependent data can be done using memcached's cas (check-and-set) operation. Each value has a unique ID (serial). For each key, store another key.dependents, which has the serial of the data, and the keys of all dependents.

When going to add a dependent, do

dependents, dep_serial = fetch(key+".dependents")
data, serial = fetch(key)
if serial != dependents[0]:
    # somebody changed the actual data
    start_over
generate_and_cache_dependent(dep_key, data)
dependents.append(dep_key)
if not cas(dependents, dep_serial):
   # somebody changed dependents
   start_over # can avoid regenerating the data if they are still at serial

When invalidating an item, do

dependents, dep_serial = fetch(key + ".dependents")
serial = update(key, new_data)
for dkey in dependents[1:]:
    delete(dkey)
dependents = [serial]
if not cas(dependents, dep_serial):
    start_over

Even in the presence of conflicting writes, these algorithms will eventually terminate, since one writer will always "get through".

Martin v. Löwis
interesting, i'll look into that!but i'd really like to wrap it into something likeset( 'section#1', 'section data', 'article#1,article#2,article#3' )then just beeing able to delete('article#1'); and then when i try to get section1 the next time it just has to regenerate it, but that could possible create race-conditions and cache deadlocks, and those arent funny either :/
possan
A: 

Velocity has support for tagging where each tag is a string. Objects can be retrieved by a tag or by multiple tags e.g. 'Condiment' AND 'Free Delivery'.

However Velocity has no support for dependencies - IIRC the Velocity team have said dependencies will not be in v1.

PhilPursglove
maybe i'll look into velocity then, but my guts tell me that memcache is the way to go :)
possan
i'll flag this as the solution.
possan
A: 

implementing dependency is quite difficult, but maybe all other features of Shared Cache (http://www.sharedcache.com || http://sharedcache.codeplex.com) will fit your needs for caching.

regards, roni