diff --git a/vendor/plugins/timed_cached_fragment/lib/timed_cache_fragment.rb b/vendor/plugins/timed_cached_fragment/lib/timed_cache_fragment.rb index 359cb83..a93307b 100644 --- a/vendor/plugins/timed_cached_fragment/lib/timed_cache_fragment.rb +++ b/vendor/plugins/timed_cached_fragment/lib/timed_cache_fragment.rb @@ -2,30 +2,53 @@ module ActionController module Cache module TimedCache - #used to store the associated timeout time of cache key - @@cache_timeout_values = {} #handles standard ERB fragments used in RHTML def cache_timeout(name={}, expire = 10.minutes.from_now, &block) unless perform_caching then block.call; return end key = fragment_cache_key(name) if is_cache_expired?(key,true) expire_timeout_fragment(key) - @@cache_timeout_values[key] = expire + set_timeout(key, expire) end cache_erb_fragment(block,name) end #handles the expiration of timeout fragment def expire_timeout_fragment(key) - @@cache_timeout_values.keys.select{|k| key === k}.each do |k| - @@cache_timeout_values[k] = nil - end - expire_fragment(/#{key}/) + delete_timeout(key) + expire_fragment(key) end #checks to see if a cache has fully expired def is_cache_expired?(name, is_key = false) key = is_key ? name : fragment_cache_key(name) - return (!@@cache_timeout_values[key]) || (@@cache_timeout_values[key] < Time.now) + timeout = get_timeout(key) + return (!timeout) || (timeout < Time.now) + end + + # from http://code.google.com/p/timedcachedfragment/issues/detail?id=1 + def cache_erb_fragment(block, name = {}, options = nil) + unless perform_caching then block.call; return end + + buffer = eval(ActionView::Base.erb_variable, block.binding) + + if cache = read_fragment(name, options) + buffer.concat(cache) + else + pos = buffer.length + block.call + write_fragment(name, buffer[pos..-1], options) + end + end + + def delete_timeout(key) + expire_fragment('timeout:' + key) end + def get_timeout(key) + read_fragment('timeout:' + key) + end + def set_timeout(key, value) + write_fragment('timeout:' + key, value) + end + end end end -- libgit2 0.21.2