lib/web_loader/cache.rb in web_loader-1.2.1 vs lib/web_loader/cache.rb in web_loader-1.3.0

- old
+ new

@@ -10,11 +10,10 @@ # __cache__055a266970912bcbd34f88692528c20e.yml # class Cache PREFIX = "__cache__" # CACHE_LIMIT = 3600 - CACHE_LIMIT = 60 def self.basename(url) Digest::MD5.hexdigest(url) end @@ -41,14 +40,14 @@ YAML.dump({"url" => url, "code" => code}, open(header_path, "w")) content_path = content_filename(dir, url) File.write(content_path, content) end - def self.clear(dir) + def self.clear(dir, cache_limit) Dir.glob("#{dir}/#{PREFIX}*.{yml,html}").each do |path| diff = Time.now - File.mtime(path) # 1時間以上昔のキャッシュは使用しない - too_old_cache = diff > CACHE_LIMIT + too_old_cache = diff > cache_limit FileUtils.rm(path) if too_old_cache end end end \ No newline at end of file