Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View ActiveSupport::Cache::MemoryStoreWithExpiry
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
module ActiveSupport
module Cache
class MemoryStoreWithExpiry < MemoryStore
 
def initialize
super
@times = {}
end
 
def write(name, value, options = nil)
if options && options[:expires_in]
@times[name] = { :cached_at => Time.now, :expires_in => options[:expires_in] }
end
super
end
 
def read(name, options = nil)
return if expired?(name)
super
end
 
private
 
def expired?(name)
return false unless @times[name]
(Time.now - @times[name][:cached_at]) > @times[name][:expires_in]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.