Sha256: 01ac90f2960512187078c88660f20029561843dfd1a61fdc107389b0c09313b3
Contents?: true
Size: 658 Bytes
Versions: 2
Compression:
Stored size: 658 Bytes
Contents
require 'rpass/storage' module RPass def self.cache @cache ||= Cache.new(RPass.storage) end class Cache CACHE_KEY = ".cache" attr_reader :storage def initialize(storage) @storage = storage end def write(name, value, duration: 0) storage.write(name, value) map = data data[name] = Time.now + duration storage.write(CACHE_KEY, data) end def read(name) map = data if !data[name] || Time.now < data[name] storage.read(name) else storage.delete(name) nil end end def data YAML.load(storage.read(CACHE_KEY)) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rpass-0.1.1 | lib/rpass/cache.rb |
rpass-0.1.0 | lib/rpass/cache.rb |