Class: Routemaster::Middleware::Cache

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

Instance Method Summary collapse

Constructor Details

#initialize(app, cache: nil, resque: nil, queue: nil) ⇒ Cache

Returns a new instance of Cache.



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

def initialize(app, cache:nil, resque:nil, queue:nil)
  @app    = app
  @cache  = cache || Routemaster::Cache.new
  @resque = resque || Resque
  @queue  = queue || Config.queue_name
end

Instance Method Details

#call(env) ⇒ Object



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

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