Created
June 20, 2009 15:12
-
-
Save phillipoertel/133179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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