Class: Flipper::Middleware::Memoizer
- Inherits:
-
Object
- Object
- Flipper::Middleware::Memoizer
- Defined in:
- lib/flipper/middleware/memoizer.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Memoizer
constructor
Public: Initializes an instance of the Memoizer middleware.
Constructor Details
#initialize(app, opts = {}) ⇒ Memoizer
Public: Initializes an instance of the Memoizer middleware. Flipper must be configured with a default instance or the flipper instance must be setup in the env of the request. You can do this by using the Flipper::Middleware::SetupEnv middleware.
app - The app this middleware is included in. opts - The Hash of options.
:preload - Boolean to preload all features or Array of Symbol feature names to preload.
Examples
use Flipper::Middleware::Memoizer
# using with preload_all features
use Flipper::Middleware::Memoizer, preload: true
# using with preload specific features
use Flipper::Middleware::Memoizer, preload: [:stats, :search, :some_feature]
23 24 25 26 27 28 29 30 31 |
# File 'lib/flipper/middleware/memoizer.rb', line 23 def initialize(app, opts = {}) if opts.is_a?(Flipper::DSL) || opts.is_a?(Proc) raise 'Flipper::Middleware::Memoizer no longer initializes with a flipper instance or block. Read more at: https://git.io/vSo31.' end @app = app @opts = opts @env_key = opts.fetch(:env_key, 'flipper') end |
Instance Method Details
#call(env) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/flipper/middleware/memoizer.rb', line 33 def call(env) request = Rack::Request.new(env) if memoize?(request) memoized_call(env) else @app.call(env) end end |