Let's say a path on my rails app got stuck in rack cache. Is there a way to say: "/games/zelda" should be removed/invalidated from rack-cache?
Asked
Active
Viewed 222 times
4
-
1What [storage](https://rtomayko.github.io/rack-cache/storage) do you use? – spickermann Mar 18 '16 at 06:59
-
@spickermann I use Dalli/memcached. – user3384741 Mar 18 '16 at 07:38
2 Answers
4
Assumtions
- Your rails app is named
MyApp
- the complete url you wish to purge is http://www.myapp.com/games/zelda
Step 1 obtain a normalized key
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
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
stored_meta = metastore.read(key)
Step 4 purge the entity store for each compression type
stored_meta.each do |sm|
entitystore.purge(sm[1]["X-Content-Digest"])
end
Step 5 purge the metastore
metastore.purge(key)
I hope this helps.

laertiades
- 1,992
- 2
- 19
- 26
0
You can either delete one key or all keys from an Memcached instance. 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:
- Delete all keys in Memcached.
- Or change the path in the URI of your Memcached Storage config and re-cache all keys.

spickermann
- 100,941
- 9
- 101
- 131