Last active
March 9, 2016 23:02
-
-
Save mtrolle/fd5707b93b64249a6e24 to your computer and use it in GitHub Desktop.
If you need to cache large datasets memcached / dalli_store might not be enough, in that case you could combine different cache strategies in Rails.
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
# Using Dalli Store gem for default caching, just use Rails.cache directly | |
# https://github.com/petergoldstein/dalli | |
Rails.cache.fetch('some-key', expires_in: 1.hour) do | |
#foo baa and a lot of work | |
end | |
# Now use Rails FileStore cache as alternative strategy by using ActiveSupport::Cache::FileStore directly | |
cache = ActiveSupport::Cache::FileStore.new File.join(Rails.root, 'tmp', 'cache', 'some-name') | |
cache.fetch('some-key', expires_in: 1.hour) do | |
# some hard work returning a huge dataset to large for memcached | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment