require ''rubygems''
require ''active_support''
cache = ActiveSupport::Cache.lookup_store(:memory_store)
#cache=Rails.cache
def cache.fetch(key,options={})
  second=options.delete(:expires_in).to_i
        raise "cache_fetch method second can not blow zero" if
second<=0
        time_tag = ((Time.now.to_i/second)*second)
        expires_key = [time_tag,key]
  p expires_key
        instance_eval{@data.delete_if{|k,v|
Time.now.to_i>k.first+second}}
        super(expires_key,options){yield}
end
puts cache.fetch(''test'',:expires_in=>3.seconds){rand}
puts cache.fetch(''test'',:expires_in=>3.seconds){rand}
sleep 4
puts cache.fetch(''test'',:expires_in=>3.seconds){rand}
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---