简体   繁体   English

Memcached依赖项

[英]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, ie if Key A is dependent on Key B , then whenever Key B is deleted or changed, Key A is also invalidated. 我正在使用memcahced (特别是Enyim memcached客户端 ),我希望能够在缓存中创建一个依赖于其他密钥的密钥,即如果密钥A依赖于密钥B ,那么每当密钥B被删除或更改时, 密钥A也无效。

If possible I would also like to make sure that data integrity is maintained in the case of a node in the cluster fails, ie if Key B is at some point unavailable, Key A should still be invalid if Key B should become invalid. 如果可能的话我也想,以确保数据的完整性保持在一个节点的集群中的失败的情况下,即,如果B密钥是在某些时候无法使用, 键A应该还是无效的,如果B密钥应该成为无效。

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? 谁能帮我吗?

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. 我最近一直在使用memcached并且我确定你正在尝试使用memcached“依旧”,但是需要从客户端处理。 Also that the data replication should happen server side and not from the client, these are 2 different domains. 此外,数据复制应该发生在服务器端而不是客户端,这些是2个不同的域。 (With memcached at least, seeing its lack of data storage logic. The point of memcached though is just that, extreme minimalism for bettter performance) (至少使用memcached,看到它缺乏数据存储逻辑。但memcached的意思就是这样,极端的极简主义表现最好)

For the data replication (protection against a physical failing cluster node) you should check out membased http://www.couchbase.org/get/couchbase/current instead. 对于数据复制(针对物理故障集群节点的保护),您应该查看成员http://www.couchbase.org/get/couchbase/current

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. 对于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.

Cheers 干杯

I don't think it's a direct solution but try creating a system of namespaces in your memcache keys, eg http://www.cakemail.com/namespacing-in-memcached/ . 我不认为这是一个直接的解决方案,但尝试在memcache密钥中创建一个名称空间系统,例如http://www.cakemail.com/namespacing-in-memcached/ In short, the keys are generated and contain the current values of other memcached keys. 简而言之,生成密钥并包含其他memcached密钥的当前值。 In the namespacing problem the idea is to invalidate a whole range of keys who are within a certain namespace. 在命名空间问题中,想法是使一系列在某个命名空间内的键无效。 This is achieved by something like incrementing the value of the namespace key, and any keys referencing the previous namespace value will not match when the key is regenerated. 这是通过增加命名空间键的值来实现的,并且在重新生成键时引用先前命名空间值的任何键都不匹配。

Your problem looks a little different, but I think that by setting up Key A to be in the Key B "namespace, if a node B was unavailable then calculating Key A 's full namespaced key eg 您的问题看起来有点不同,但我认为通过将密钥A设置为密钥B “命名空间,如果节点B不可用,则计算密钥A的完整命名空间密钥,例如

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

will return false, thus allowing you to determine that B is unavailable and invalidate the cache lookup for Key A . 将返回false,从而允许您确定B不可用并使密钥A的缓存查找无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM