Skip to content

Instantly share code, notes, and snippets.

@HotFusionMan
Created August 30, 2013 03:48
Show Gist options
  • Save HotFusionMan/6386156 to your computer and use it in GitHub Desktop.
Save HotFusionMan/6386156 to your computer and use it in GitHub Desktop.
How to expire just one view fragment from the Rails cache

In the following code, I assume there's a cache_key_for method defined in ApplicationHelper that's being used by the Rails app to compute the key used for caching the asset objects. If that isn't the case in your app, you won't need the helper calls, but you'll need to supply whatever code you're actually using for determining cache key values.

in Rails console:

controller = ApplicationController.new
controller.expire_fragment(helper.cache_key_for(asset))

in other code (where the "helper" method is not defined):

include ApplicationHelper
controller = ApplicationController.new
controller.expire_fragment(cache_key_for(asset))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment