{"record":{"id":"fe6d00e895255053","repo":"flippercloud/flipper","slug":"flipper-middleware-memoizer-no-longer-initialize","errorCode":null,"errorMessage":"Flipper::Middleware::Memoizer no longer initializes with a flipper instance or block. Read more at: https://git.io/vSo31.","messagePattern":"Flipper::Middleware::Memoizer no longer initializes with a flipper instance or block\\. Read more at: https://git\\.io/vSo31\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/flipper/middleware/memoizer.rb","lineNumber":33,"sourceCode":"      #   use Flipper::Middleware::Memoizer\n      #\n      #   # using with preload_all features\n      #   use Flipper::Middleware::Memoizer, preload: true\n      #\n      #   # using with preload specific features\n      #   use Flipper::Middleware::Memoizer, preload: [:stats, :search, :some_feature]\n      #\n      #   # using with preload block that returns true/false\n      #   use Flipper::Middleware::Memoizer, preload: ->(request) { !request.path.start_with?('/assets') }\n      #\n      #   # using with preload block that returns specific features\n      #   use Flipper::Middleware::Memoizer, preload: ->(request) {\n      #     request.path.starts_with?('/admin') ? [:stats, :search] : false\n      #   }\n      #\n      def initialize(app, opts = {})\n        if opts.is_a?(Flipper::DSL) || opts.is_a?(Proc)\n          raise 'Flipper::Middleware::Memoizer no longer initializes with a flipper instance or block. Read more at: https://git.io/vSo31.'\n        end\n\n        @app = app\n        @opts = opts\n        @env_key = opts.fetch(:env_key, 'flipper')\n      end\n\n      def call(env)\n        request = Rack::Request.new(env)\n\n        if memoize?(request)\n          memoized_call(request)\n        else\n          @app.call(env)\n        end\n      end\n\n      private","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/flippercloud/flipper/blob/1f86de3ec91521585b156445e156642938b19cb0/lib/flipper/middleware/memoizer.rb#L15-L51","documentation":"Flipper 0.7 removed building the Memoizer middleware around a specific instance: initialize now takes only a Hash of options (:preload, :if, :unless, :env_key) and raises immediately when the second argument is a Flipper::DSL instance or a Proc (lib/flipper/middleware/memoizer.rb:31-39). The instance to memoize must come from the Rack env (set by Flipper::Middleware::SetupEnv) or from Flipper's configured default via Flipper.configure. The guard fails fast at boot instead of silently ignoring the old argument.","triggerScenarios":"Building a Rack/Rails stack with use Flipper::Middleware::Memoizer, Flipper.new(adapter), or passing a lambda/block as the second argument (use Flipper::Middleware::Memoizer, -> { Flipper.new(adapter) }) — initialize sees a Flipper::DSL or Proc in opts and raises while the middleware stack is constructed, before any request is served.","commonSituations":"Upgrading an app from flipper pre-0.7 to anything newer; copy-pasting middleware snippets from old blog posts, StackOverflow answers, or the pre-0.7 README; initializers that lazily built the flipper instance with a block.","solutions":["Move the instance into configuration and mount the memoizer with Hash options only: Flipper.configure { |config| config.default { Flipper.new(adapter) } } then use Flipper::Middleware::Memoizer, preload: true.","If other middleware needs the instance in env, insert Flipper::Middleware::SetupEnv (which still accepts an instance or block) in front of the Memoizer.","Remove the instance/block argument entirely — env_key defaults to 'flipper' and the memoizer falls back to the configured default instance."],"exampleFix":"# before (pre-0.7 API)\nuse Flipper::Middleware::Memoizer, Flipper.new(redis_adapter)\n\n# after\nFlipper.configure do |config|\n  config.default { Flipper.new(redis_adapter) }\nend\nuse Flipper::Middleware::Memoizer, preload: true","handlingStrategy":"validation","validationCode":"opts = { preload: true }\nraise ArgumentError, 'Flipper::Middleware::Memoizer takes a Hash of options only' unless opts.is_a?(Hash)\nuse Flipper::Middleware::Memoizer, opts","typeGuard":"def memoizer_opts?(arg)\n  arg.is_a?(Hash)\nend","tryCatchPattern":null,"preventionTips":["After any flipper upgrade, grep the app for 'Middleware::Memoizer' and check second arguments before boot.","Configure the instance via Flipper.configure (config.default) instead of passing it to middleware.","Take middleware snippets from the current README/CHANGELOG, not old search results.","Boot the app in CI to catch middleware-construction raises before deploy."],"tags":["ruby","rack","middleware","breaking-change","upgrade","flipper"],"backgroundTag":"middleware-initializer-signature-changed","analyzedSha":"1f86de3ec91521585b156445e156642938b19cb0","analyzedAt":"2026-08-23T04:36:09.896Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}