Skip to content

Instantly share code, notes, and snippets.

@mtrolle
Last active March 9, 2016 23:02
Show Gist options
  • Save mtrolle/fd5707b93b64249a6e24 to your computer and use it in GitHub Desktop.
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.
# 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