R – Any distributed cache systems that allows for tagging content

appfabricdistributed-cachingmemcachedtagging

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

Best Answer

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".

Related Topic