Class: Routemaster::Middleware::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/routemaster/middleware/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Cache

Returns a new instance of Cache.



10
11
12
13
14
15
# File 'lib/routemaster/middleware/cache.rb', line 10

def initialize(app, options = {})
  @app    = app
  @cache  = options.fetch(:cache) { Routemaster::Cache.new }
  @client = options.fetch(:client) { Routemaster::Jobs::Client.new }
  @queue  = options.fetch(:queue) { Config.queue_name }
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
# File 'lib/routemaster/middleware/cache.rb', line 17

def call(env)
  env.fetch('routemaster.dirty', []).each do |url|
    @client.enqueue(@queue, Routemaster::Jobs::CacheAndSweep, url)
  end
  @app.call(env)
end