class CacheUpdater
  constructor: (@cache, @backend) ->
    throw new Error("Cache cannot be null.") unless @cache?
    throw new Error("Backend cannot be null.") unless @backend?
    @resourcesToUpdate = [];
    setInterval((=> @doUpdate), CacheUpdater.updateInterval);

  update: (url, callback=->)->
    @resourcesToUpdate = [];
    @backend.download url, (resource)=>
      key = @cache.keyFor(url);
      @cache.set key, resource if resource?
      callback.apply @, [ resource ]

CacheUpdater.updateInterval = 60 * 1000;
module.exports = CacheUpdater;