Created
November 16, 2019 19:37
-
-
Save robotzhang/b5d0fdc5aa6c508dfe0259bbc20b0446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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