1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch/http/rack_cache.rb

62 lines
1 KiB
Ruby
Raw Normal View History

2010-09-13 17:03:06 -04:00
require "rack/cache"
require "rack/cache/context"
require "active_support/cache"
module ActionDispatch
class RailsMetaStore < Rack::Cache::MetaStore
def self.resolve(uri)
new
end
2012-01-17 11:53:09 -05:00
def initialize(store = Rails.cache)
2010-09-13 17:03:06 -04:00
@store = store
end
def read(key)
2011-05-17 17:32:52 -04:00
if data = @store.read(key)
Marshal.load(data)
else
[]
end
2010-09-13 17:03:06 -04:00
end
def write(key, value)
2011-05-17 17:32:52 -04:00
@store.write(key, Marshal.dump(value))
2010-09-13 17:03:06 -04:00
end
::Rack::Cache::MetaStore::RAILS = self
end
class RailsEntityStore < Rack::Cache::EntityStore
def self.resolve(uri)
new
end
2012-01-17 11:53:09 -05:00
def initialize(store = Rails.cache)
2010-09-13 17:03:06 -04:00
@store = store
end
def exist?(key)
@store.exist?(key)
end
def open(key)
@store.read(key)
end
def read(key)
body = open(key)
body.join if body
end
def write(body)
buf = []
key, size = slurp(body) { |part| buf << part }
@store.write(key, buf)
[key, size]
end
::Rack::Cache::EntityStore::RAILS = self
end
end