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
Matthew Draper 87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30

61 lines
1 KiB
Ruby

require "rack/cache"
require "rack/cache/context"
require "active_support/cache"
module ActionDispatch
class RailsMetaStore < Rack::Cache::MetaStore
def self.resolve(uri)
new
end
def initialize(store = Rails.cache)
@store = store
end
def read(key)
if data = @store.read(key)
Marshal.load(data)
else
[]
end
end
def write(key, value)
@store.write(key, Marshal.dump(value))
end
::Rack::Cache::MetaStore::RAILS = self
end
class RailsEntityStore < Rack::Cache::EntityStore
def self.resolve(uri)
new
end
def initialize(store = Rails.cache)
@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