7

我正在使用memcahced(特别是 Enyim memcached 客户端)并且我希望能够使缓存中的键依赖于其他键,即如果键 A依赖于键 B,那么每当键 B被删除或更改时,键A也无效。

如果可能的话,我还想确保在集群中的一个节点发生故障的情况下保持数据完整性,即如果密钥 B在某些时候不可用,如果密钥 B应该变得无效,那么密钥 A应该仍然无效。

基于这篇文章,我相信这是可能的,但我正在努力理解该算法以说服自己如何/为什么它有效。

谁能帮我吗?

4

2 回答 2

7

我最近一直在使用 memcached,我确信你试图用 depencies 做的事情对于 memcached “原样”是不可能的,但需要从客户端处理。此外,数据复制应该发生在服务器端而不是来自客户端,这是 2 个不同的域。(至少使用 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.

干杯

于 2011-10-03T15:23:43.370 回答
0

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

您的问题看起来有点不同,但我认为通过将Key A设置在Key B “命名空间中,如果节点 B 不可用,则计算Key A的完整命名空间密钥,例如

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

将返回 false,从而允许您确定 B 不可用并使Key A的缓存查找无效。

于 2011-09-30T03:36:11.043 回答