Sha256: c8281dc59902cc3edac9cd27c33400b77d4609be51473f26cc30f3db48b52c86

Contents?: true

Size: 1.2 KB

Versions: 96

Compression:

Stored size: 1.2 KB

Contents

require 'rack/body_proxy'
require 'rack/utils'

module ActiveSupport
  module Cache
    module Strategy
      module LocalCache

        #--
        # This class wraps up local storage for middlewares. Only the middleware method should
        # construct them.
        class Middleware # :nodoc:
          attr_reader :name, :local_cache_key

          def initialize(name, local_cache_key)
            @name             = name
            @local_cache_key = local_cache_key
            @app              = nil
          end

          def new(app)
            @app = app
            self
          end

          def call(env)
            LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new)
            response = @app.call(env)
            response[2] = ::Rack::BodyProxy.new(response[2]) do
              LocalCacheRegistry.set_cache_for(local_cache_key, nil)
            end
            response
          rescue Rack::Utils::InvalidParameterError
            LocalCacheRegistry.set_cache_for(local_cache_key, nil)
            [400, {}, []]
          rescue Exception
            LocalCacheRegistry.set_cache_for(local_cache_key, nil)
            raise
          end
        end
      end
    end
  end
end

Version data entries

96 entries across 91 versions & 14 rubygems

Version Path
activesupport-4.2.11.3 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.11.2 lib/active_support/cache/strategy/local_cache_middleware.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/cache/strategy/local_cache_middleware.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.11.1 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.11 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.10 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.10.rc1 lib/active_support/cache/strategy/local_cache_middleware.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.9 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.9.rc2 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.2.9.rc1 lib/active_support/cache/strategy/local_cache_middleware.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-4.2.8/lib/active_support/cache/strategy/local_cache_middleware.rb
lazy_record-0.2.1 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb
lazy_record-0.2.0 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb
lazy_record-0.1.9 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb
lazy_record-0.1.8 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb
lazy_record-0.1.7 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb