Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipoertel/133179 to your computer and use it in GitHub Desktop.
Save phillipoertel/133179 to your computer and use it in GitHub Desktop.
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