Sha256: 5f0b8360beb74c1e9f8ac8a62ddd9b81cb4d4b684d4df7d969a7678b190b79b7
Contents?: true
Size: 1.42 KB
Versions: 20
Compression:
Stored size: 1.42 KB
Contents
module Moneta module Expires def check_expired(key) if @expiration[key] && Time.now > @expiration[key] @expiration.delete(key) self.delete(key) end end def key?(key) check_expired(key) super end def [](key) check_expired(key) super end def fetch(key, default = nil, &blk) check_expired(key) super end def delete(key) check_expired(key) super end def update_key(key, options) update_options(key, options) end def store(key, value, options = {}) ret = super(key, value) update_options(key, options) ret end private def update_options(key, options) if options[:expires_in] @expiration[key] = (Time.now + options[:expires_in]) end end end module StringExpires include Expires def check_expired(key) if @expiration[key] && Time.now > Time.at(@expiration[key].to_i) @expiration.delete(key) delete(key) end end private def update_options(key, options) if options[:expires_in] @expiration[key] = (Time.now + options[:expires_in]).to_i.to_s end end end module Defaults def fetch(key, value = nil) value ||= block_given? ? yield(key) : default self[key] || value end def store(key, value, options = {}) self[key] = value end end end
Version data entries
20 entries across 20 versions & 9 rubygems