Class: Pgbus::Streams::WatermarkCacheMiddleware
- Inherits:
-
Object
- Object
- Pgbus::Streams::WatermarkCacheMiddleware
- Defined in:
- lib/pgbus/streams/watermark_cache_middleware.rb
Overview
Rack middleware that clears the per-request thread-local watermark cache used by ‘Pgbus::StreamsHelper#pgbus_stream_from`. Without this middleware, a subsequent request served by the same thread would see stale `current_msg_id` values from the previous render — the pgbus_stream_from helper caches watermark lookups within a single request to avoid N+1 queries when a page uses multiple streams, and the cache would leak without a per-request boundary.
Installed automatically by ‘Pgbus::Engine` at boot.
Constant Summary collapse
- CACHE_KEY =
:pgbus_streams_watermark_cache
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ WatermarkCacheMiddleware
constructor
A new instance of WatermarkCacheMiddleware.
Constructor Details
#initialize(app) ⇒ WatermarkCacheMiddleware
Returns a new instance of WatermarkCacheMiddleware.
17 18 19 |
# File 'lib/pgbus/streams/watermark_cache_middleware.rb', line 17 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 |
# File 'lib/pgbus/streams/watermark_cache_middleware.rb', line 21 def call(env) @app.call(env) ensure Thread.current[CACHE_KEY] = nil end |