Sha256: 7e9ab00c99fe8be952c0580dbff702c96fd04167c0ed36e70fc85aa179214638

Contents?: true

Size: 1.03 KB

Versions: 43

Compression:

Stored size: 1.03 KB

Contents

require 'rack/body_proxy'
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 Exception
            LocalCacheRegistry.set_cache_for(local_cache_key, nil)
            raise
          end
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 4 rubygems

Version Path
activesupport-4.1.16 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.16.rc1 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.15 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.15.rc1 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.14.2 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.14.1 lib/active_support/cache/strategy/local_cache_middleware.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/cache/strategy/local_cache_middleware.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/cache/strategy/local_cache_middleware.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.14 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.14.rc2 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.14.rc1 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.13 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.13.rc1 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.12 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.12.rc1 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.11 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.10 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.10.rc4 lib/active_support/cache/strategy/local_cache_middleware.rb
activesupport-4.1.10.rc3 lib/active_support/cache/strategy/local_cache_middleware.rb