Skip to content

Instantly share code, notes, and snippets.

@YanhaoYang
Created January 10, 2015 15:06
Show Gist options
  • Save YanhaoYang/84df4b7e1df4313bbbf5 to your computer and use it in GitHub Desktop.
Save YanhaoYang/84df4b7e1df4313bbbf5 to your computer and use it in GitHub Desktop.
Cache GET requests of ActiveResource
module ArCache
extend ActiveSupport::Concern
def get(path, headers = {})
cache_key = "ar_cache_#{path}"
Rails.cache.fetch(cache_key, expires_in: 60.seconds) do
super
end
end
end
ActiveResource::Connection.send(:prepend, ArCache)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment