Memcached依赖项

Jus*_*tin 7 memcached caching enyim

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

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

基于这篇文章我相信这是可能的,但我很难理解这个算法足以说服自己如何/为什么这样做.

谁能帮我吗?

sma*_*sey 7

我最近一直在使用memcached并且我确定你正在尝试使用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.
Run Code Online (Sandbox Code Playgroud)

干杯


Ian*_*Ian 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>"
Run Code Online (Sandbox Code Playgroud)

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