Skip to content

Commit

Permalink
page caching removes the cookies and sets a 5 min cache-control timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardochimal authored and Adam Wiggins committed Nov 24, 2008
1 parent dc81a04 commit ecd52a0
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions actionpack/lib/action_controller/caching/pages.rb
Expand Up @@ -64,21 +64,14 @@ module ClassMethods
# expire_page "/lists/show"
def expire_page(path)
return unless perform_caching

benchmark "Expired page: #{page_cache_file(path)}" do
File.delete(page_cache_path(path)) if File.exist?(page_cache_path(path))
end
# NOOP. This won't work with multiple slugs in the cloud
end

# Manually cache the +content+ in the key determined by +path+. Example:
# cache_page "I'm the cached content", "/lists/show"
def cache_page(content, path)
return unless perform_caching

benchmark "Cached page: #{page_cache_file(path)}" do
FileUtils.makedirs(File.dirname(page_cache_path(path)))
File.open(page_cache_path(path), "wb+") { |f| f.write(content) }
end
# NOOP. This won't work with multiple slugs in the cloud
end

# Caches the +actions+ using the page-caching approach that'll store the cache in a path within the page_cache_directory that
Expand All @@ -94,7 +87,10 @@ def cache_page(content, path)
def caches_page(*actions)
return unless perform_caching
options = actions.extract_options!
after_filter({:only => actions}.merge(options)) { |c| c.cache_page }
after_filter({:only => actions}.merge(options)) do |c|
c.response.headers['Cache-Control'] = 'public; max-age=360' # there's no one size fits all so 5 min is a good compromise
c.response.headers.delete('cookie') # caching the page means no cookies.

This comment has been minimized.

Copy link
@isc

isc Apr 14, 2011

Does it really delete the cookie header ? Shouldn't it be c.response.headers.delete('Set-Cookie') ?

end
end

private
Expand Down Expand Up @@ -151,4 +147,4 @@ def caching_allowed
end
end
end
end
end

0 comments on commit ecd52a0

Please sign in to comment.