简体   繁体   English

从rack-cache中取消个别密钥?

[英]Invalidating individual keys from rack-cache?

Let's say a path on my rails app got stuck in rack cache. 假设我的rails app上的路径卡在机架缓存中。 Is there a way to say: "/games/zelda" should be removed/invalidated from rack-cache? 有没有办法说:“/ games / zelda”应该从机架缓存中删除/无效?

Assumtions Assumtions

  1. Your rails app is named MyApp 您的rails应用程序名为MyApp
  2. the complete url you wish to purge is http://www.myapp.com/games/zelda 您要清除的完整网址是http://www.myapp.com/games/zelda

Step 1 obtain a normalized key 步骤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))

Step 2 retrieve storage objects 第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)

Step 3 retrieve the metadata 第3步检索元数据

stored_meta = metastore.read(key)

Step 4 purge the entity store for each compression type 步骤4清除每个压缩类型的实体存储

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

Step 5 purge the metastore 步骤5清除Metastore

metastore.purge(key)

I hope this helps. 我希望这有帮助。

You can either delete one key or all keys from an Memcached instance. 您可以从Memcached实例中删除一个密钥或所有密钥。 Unfortunately doesn't allow to list all keys. 不幸的是,不允许列出所有密钥。 Therefore you cannot iterate over all keys and just delete the one you want to invalidate. 因此,您无法迭代所有键,只删除要使其无效的键。

That said I see two options: 那说我看到两个选择:

  1. Delete all keys in Memcached. 删除Memcached中的所有键。
  2. Or change the path in the URI of your Memcached Storage config and re-cache all keys. 或者更改Memcached Storage配置的URI中的路径并重新缓存所有密钥。

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

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