class HTTParty::Icebox::Store::FileStore
Store
objects on the filesystem¶ ↑
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
HTTParty::Icebox::Store::AbstractStore::new
# File lib/shin/httparty_icebox.rb, line 201 def initialize(options={}) super options[:location] ||= Dir::tmpdir @path = Pathname.new( options[:location] ) FileUtils.mkdir_p( @path ) self end
Public Instance Methods
exists?(key)
click to toggle source
# File lib/shin/httparty_icebox.rb, line 218 def exists?(key) File.exists?( @path.join(key) ) end
get(key)
click to toggle source
# File lib/shin/httparty_icebox.rb, line 213 def get(key) data = Marshal.load(File.new(@path.join(key))) Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})") data end
set(key, value)
click to toggle source
# File lib/shin/httparty_icebox.rb, line 208 def set(key, value) Cache.logger.info("Cache: set (#{key})") File.open( @path.join(key), 'w' ) { |file| Marshal.dump(value, file) } true end
stale?(key)
click to toggle source
# File lib/shin/httparty_icebox.rb, line 221 def stale?(key) return true unless exists?(key) Time.now - created(key) > @timeout end
Private Instance Methods
created(key)
click to toggle source
# File lib/shin/httparty_icebox.rb, line 226 def created(key) File.mtime( @path.join(key) ) end