簡體   English   中英

從rack-cache中取消個別密鑰?

[英]Invalidating individual keys from rack-cache?

假設我的rails app上的路徑卡在機架緩存中。 有沒有辦法說:“/ games / zelda”應該從機架緩存中刪除/無效?

Assumtions

  1. 您的rails應用程序名為MyApp
  2. 您要清除的完整網址是http://www.myapp.com/games/zelda

步驟1獲取規范化密鑰

mock_request = Rack::MockRequest.env_for('/games/zelda', {"SERVER_NAME"=>"www.myapp.com"})
key = Rack::Cache::Key.call(Rack::Cache::Request.new(mock_request))

第2步檢索存儲對象

metastore_uri = MyApp::Application.config.action_dispatch.rack_cache[:metastore]
entitystore_uri = MyApp::Application.config.action_dispatch.rack_cache[:entitystore]

metastore = Rack::Cache::Storage.instance.resolve_metastore_uri(metastore_uri)
entitystore = Rack::Cache::Storage.instance.resolve_entitystore_uri(entitystore_uri)

第3步檢索元數據

stored_meta = metastore.read(key)

步驟4清除每個壓縮類型的實體存儲

stored_meta.each do |sm|
  entitystore.purge(sm[1]["X-Content-Digest"])
end

步驟5清除Metastore

metastore.purge(key)

我希望這有幫助。

您可以從Memcached實例中刪除一個密鑰或所有密鑰。 不幸的是,不允許列出所有密鑰。 因此,您無法迭代所有鍵,只刪除要使其無效的鍵。

那說我看到兩個選擇:

  1. 刪除Memcached中的所有鍵。
  2. 或者更改Memcached Storage配置的URI中的路徑並重新緩存所有密鑰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM