Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memcached dependent items

I'm using memcahced (specifically the Enyim memcached client) and I would like to able to make a keys in the cache dependant on other keys, i.e. if Key A is dependent on Key B, then whenever Key B is deleted or changed, Key A is also invalidated.

If possible I would also like to make sure that data integrity is maintained in the case of a node in the cluster fails, i.e. if Key B is at some point unavailable, Key A should still be invalid if Key B should become invalid.

Based on this post I believe that this is possible, but I'm struggling to understand the algorithm enough to convince myself how / why this works.

Can anyone help me out?

like image 519
Justin Avatar asked Feb 28 '11 11:02

Justin


1 Answers

I've been using memcached quite a bit lately and I'm sure what you're trying to do with depencies isn't possible with memcached "as is" but would need to be handled from client side. Also that the data replication should happen server side and not from the client, these are 2 different domains. (With memcached at least, seeing its lack of data storage logic. The point of memcached though is just that, extreme minimalism for bettter performance)

For the data replication (protection against a physical failing cluster node) you should check out membased http://www.couchbase.org/get/couchbase/current instead.

For the deps algorithm, I could see something like this in a client: For any given key there is a suspected additional key holding the list/array of dependant keys.

# - delete a key, recursive:
function deleteKey( keyname ):
    deps = client.getDeps( keyname ) #
    foreach ( deps as dep ):
        deleteKey( dep )
        memcached.delete( dep )
    endeach
    memcached.delete( keyname )
endfunction

# return the list of keynames or an empty list if the key doesnt exist
function client.getDeps( keyname ):
    return memcached.get( key_name + "_deps" ) or array()
endfunction

# Key "demokey1" and its counterpart "demokey1_deps". In the list of keys stored in
# "demokey1_deps" there is "demokey2" and "demokey3".
deleteKey( "demokey1" );
# this would first perform a memcached get on "demokey1_deps" then with the
# value returned as a list of keys ("demokey2" and "demokey3") run deleteKey()
# on each of them.

Cheers

like image 168
smassey Avatar answered Nov 12 '22 21:11

smassey