module Fc2
Constants
- VERSION
Public Class Methods
all_clear()
click to toggle source
# File lib/fc2.rb, line 30 def self.all_clear FileUtils.rm_r(cache_dir, secure: true) if File.exist? cache_dir end
fetch(key: caller.first, expires_in: 300) { || ... }
click to toggle source
# File lib/fc2.rb, line 23 def self.fetch(key: caller.first, expires_in: 300) key = Digest::MD5.hexdigest(key) path = File.expand_path(key, cache_dir) return Marshal.load(File.read(path)) if use_cache?(path, expires_in) dump(path, yield) end
included(base)
click to toggle source
# File lib/fc2.rb, line 7 def self.included(base) base.extend(ClassMethods) end
Private Class Methods
cache_dir()
click to toggle source
# File lib/fc2.rb, line 36 def self.cache_dir File.expand_path("org.yoshiori.fc2", Dir.tmpdir) end
dump(path, obj)
click to toggle source
# File lib/fc2.rb, line 44 def self.dump(path, obj) FileUtils.mkdir_p(cache_dir) unless File.exist? cache_dir File.open(path, "w") { |f| f.write(Marshal.dump(obj)) } obj end
paths()
click to toggle source
# File lib/fc2.rb, line 50 def self.paths @paths ||= [] end
use_cache?(path, expires_in)
click to toggle source
# File lib/fc2.rb, line 40 def self.use_cache?(path, expires_in) File.exist?(path) && (Time.now - File::Stat.new(path).mtime) <= expires_in end