Sha256: 5db2c94e16eacd30378617d3a2fd5e0b3d6ffebb82b69bbb9d63c98ae8f62d04
Contents?: true
Size: 1.06 KB
Versions: 4
Compression:
Stored size: 1.06 KB
Contents
class PublicSuffixList class CacheFile def initialize(config) @config = config end def cache? @config.cache_dir && File.directory?(@config.cache_dir) && true end def file File.join(@config.cache_dir, URI.parse(@config.url).path.split("/").last + ".cache") if cache? end def exist? File.exist?(file) if cache? end def delete File.delete(file) if exist? end def load_data open(file, "r") { |f| @data = Marshal.load(f) } if exist? end def dump_data open(file, "w") { |f| Marshal.dump(@data, f) } if cache? end def data @data or (load_data and @data) or @data = {:created_at => Time.now, :tag => rand(36**8).to_s(36)} end def data=(data) @data = data and dump_data end def [](key) data[key] end def []=(key, value) data[key] = value and dump_data end def expired? !cache? or !([0, nil].include?(@config.cache_expiry_period) or data[:created_at] + @config.cache_expiry_period > Time.now) end end end
Version data entries
4 entries across 4 versions & 1 rubygems