2011-02-28 56 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. 

乾杯

相關問題