Skip to content

Instantly share code, notes, and snippets.

@robotzhang
Created November 16, 2019 19:37
Show Gist options
  • Save robotzhang/b5d0fdc5aa6c508dfe0259bbc20b0446 to your computer and use it in GitHub Desktop.
Save robotzhang/b5d0fdc5aa6c508dfe0259bbc20b0446 to your computer and use it in GitHub Desktop.
module CachingHelper
def with_caching
cache_store_type_origin = Rails.application.config.cache_store
cache_store_origin = Rails.cache
Rails.application.config.cache_store = [
:memory_store, {:size => 64.megabytes }
]
Rails.cache = ActiveSupport::Cache::MemoryStore.new(
:expires_in => 1.minute
)
yield
ensure
Rails.cache.clear
Rails.cache = cache_store_origin
Rails.application.config.cache_store = cache_store_type_origin
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment