Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dux committed Apr 2, 2011
1 parent 4b3342b commit 11b7c17
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/cache_extended.rb
Expand Up @@ -59,23 +59,26 @@ def xcache(*obj)
return false unless flash.keys.blank?
return false if @NO_CACHE

etag_list = []

max_time = (Time.now - 1.year).utc

obj.each do |el|
if el.respond_to? :before_create # is model
ltime = el[:updated_at] if el[:updated_at]
ltime = el[:created_at] if ! ltime && el[:created_at]
raise "OBJECT [#{el.class.name}] has no updated_at or created_at fields" unless ltime
max_time = ltime if ltime > max_time
if el[:updated_at]
etag_list.push(el[:updated_at].to_i)
else
etag_list.push(%{#{el.class.name}:#{el.id}})
end
elsif el.kind_of? ActiveSupport::TimeWithZone
max_time = el if el > max_time
etag_list << el.to_i
elsif el.class.name == 'NilClass'
nil
else
raise "UNKNOWN OBJECT [#{el.class.name}] for etag"
end
end

current_user && ! @HTTP_PUBLIC ? fresh_when(:etag=>[current_user, obj, request.path], :last_modified=>max_time.utc) : fresh_when(:etag=>[obj, request.path], :last_modified=>max_time.utc, :public=>true)
fresh_when(:etag=>etag_list.join('-'), :public=> current_user ? false : true)
end
end

0 comments on commit 11b7c17

Please sign in to comment.