2011-02-28 54 views
7

我使用memcahced(特别是Enyim memcached client),我希望能够使在高速缓存中的键依赖于其他键,也就是说,如果键A取决于键B,那么无论什么时候密钥B被删除或更改,密钥A也被无效。Memcached的依赖项

如果可能的话我也想,以确保数据的完整性保持在一个节点的集群中的情况下失败,也就是说,如果键B是在某些时候无法使用,键A仍应若无效密钥B应该失效。

基于this post我相信这是可能的,但我很努力地理解算法,足以说服自己如何/为什么这会起作用。

任何人都可以帮我吗?

回答

0

我不认为这是一个直接的解决方案,但尝试在您的memcache密钥中创建一个名称空间系统,例如, http://www.cakemail.com/namespacing-in-memcached/。简而言之,密钥会生成并包含其他memcached密钥的当前值。在命名空间问题中,这个想法是使位于特定命名空间内的整个键范围无效。这可以通过增加名称空间键的值来实现,并且在重新生成键时,任何引用前一个名称空间值的键都不会匹配。

你的问题看起来有点不同,但我认为,通过设立键A是在键B“命名空间,如果节点B是不可用,那么计算键A的完整名称空间的关键例如

"Key A|Key B:<whatever Key B value is>" 

将返回false,从而使您能够确定B是不可用和键A无效缓存查找。

7

我最近我一直在使用memcached,并且我确定你正在尝试使用依赖关系对于memcached来说“按原样”是不可能的,但是需要从客户端进行处理。此外,数据复制应该发生在服务器端而不是客户端,这些是两个不同的域。 (至少在memcached中,看到它缺乏数据存储逻辑,memcached的重点在于极端的极简主义性能)

对于数据复制(针对物理故障集群节点的保护),您应该签出代替http://www.couchbase.org/get/couchbase/current

对于deps算法,我可以在客户端看到类似这样的内容:对于任何给定的键,都有一个可疑的附加键,其中包含相关键的列表/数组。

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

干杯

相关问题