Sha256: 19c6688ba88a034bc6742ed0866457e5b04d55cc81b94a17efec3bf813c2d8be

Contents?: true

Size: 1.1 KB

Versions: 24

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

# :enddoc:

# :markup: markdown

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

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
actionpack-8.0.2 lib/action_dispatch/http/rack_cache.rb
actionpack-8.0.1 lib/action_dispatch/http/rack_cache.rb
actionpack-8.0.0.1 lib/action_dispatch/http/rack_cache.rb
actionpack-7.2.2.1 lib/action_dispatch/http/rack_cache.rb
actionpack-8.0.0 lib/action_dispatch/http/rack_cache.rb
actionpack-7.2.2 lib/action_dispatch/http/rack_cache.rb
actionpack-8.0.0.rc2 lib/action_dispatch/http/rack_cache.rb
actionpack-7.2.1.2 lib/action_dispatch/http/rack_cache.rb
actionpack-8.0.0.rc1 lib/action_dispatch/http/rack_cache.rb
actionpack-7.2.1.1 lib/action_dispatch/http/rack_cache.rb
actionpack-8.0.0.beta1 lib/action_dispatch/http/rack_cache.rb
omg-actionpack-8.0.0.alpha9 lib/action_dispatch/http/rack_cache.rb
omg-actionpack-8.0.0.alpha8 lib/action_dispatch/http/rack_cache.rb
omg-actionpack-8.0.0.alpha7 lib/action_dispatch/http/rack_cache.rb
omg-actionpack-8.0.0.alpha4 lib/action_dispatch/http/rack_cache.rb
omg-actionpack-8.0.0.alpha3 lib/action_dispatch/http/rack_cache.rb
omg-actionpack-8.0.0.alpha2 lib/action_dispatch/http/rack_cache.rb
omg-actionpack-8.0.0.alpha1 lib/action_dispatch/http/rack_cache.rb
actionpack-7.2.1 lib/action_dispatch/http/rack_cache.rb
actionpack-7.2.0 lib/action_dispatch/http/rack_cache.rb