Skip to content

Instantly share code, notes, and snippets.

@marcroberts
Created October 25, 2012 14:20
Show Gist options
  • Select an option

  • Save marcroberts/3952804 to your computer and use it in GitHub Desktop.

Select an option

Save marcroberts/3952804 to your computer and use it in GitHub Desktop.
Use IronCache as a Rack::Cache metastore with Rails 3.2 on Heroku
require 'rack/cache'
require 'rack/cache/storage'
require 'rack/cache/metastore'
require 'iron_cache'
class IronCache::MetaStore < Rack::Cache::MetaStore
def initialize
@cache = IronCache::Client.new.cache('metastore')
end
def read key
obj = @cache.get hexdigest(key)
obj ? Marshal.load(obj.value) : []
end
def write key, negotiations
@cache.put hexdigest(key), Marshal.dump(negotiations)
end
def purge key
@cache.delete hexdigest(key)
end
def self.resolve(uri)
new
end
end
class Rack::Cache::MetaStore
if ENV['RAILS_GROUPS'] == 'assets'
IRCONCACHE = Rack::Cache::MetaStore::Heap
else
IRONCACHE = IronCache::MetaStore
end
end
#
#
#
config.action_dispatch.rack_cache = {
:metastore => 'ironcache:/',
:entitystore => 'file:tmp/cache/rack/body',
:allow_reload => false
}
#
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment