lib/routemaster/jobs/cache_and_sweep.rb in routemaster-drain-2.5.1 vs lib/routemaster/jobs/cache_and_sweep.rb in routemaster-drain-2.5.2
- old
+ new
@@ -1,20 +1,27 @@
require 'routemaster/cache'
require 'routemaster/dirty/map'
module Routemaster
module Jobs
- # Caches a URL using {Cache}, and sweeps the dirty map
- # if sucessful.
+ # Caches a URL using {Cache} and sweeps the dirty map if successful.
+ # Busts the cache if the resource was deleted.
class CacheAndSweep
def perform(url)
Dirty::Map.new.sweep_one(url) do
begin
- Routemaster::Cache.new.get(url)
+ cache.get(url)
rescue Errors::ResourceNotFound
- true # nothing to cache, remove the element from dirty
+ cache.bust(url)
+ true
end
end
+ end
+
+ private
+
+ def cache
+ @cache ||= Routemaster::Cache.new
end
end
end
end