Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 4706 Bytes
1 | module ActionController |
2 | class AbstractResponse |
3 | |
4 | # This isn't just +attr_accessor :lifetime+ because we need to trick components into doing |
5 | # the right thing--it should be possible to do +lifetime = 1.hour+ in a component and have |
6 | # the lifetime carried back to the original response. Unfortunately, components are called |
7 | # with their own copy of the parent's response object. Fortunately, the copy uses |
8 | # +dup+, so if we shove the actual lifetime into a hash (or anything even slighty complex), |
9 | # the +dup+ will leave the parent response and the child response sharing the same |
10 | # hash, so the lifetime will become a shared resource and The Right Thing will happen. |
11 | def lifetime |
12 | @lifetime[:time] |
13 | end |
14 | |
15 | def lifetime=(seconds) |
16 | # Only allow the lifetime to be lowered--if one component wants |
17 | # lifetime=3.hours and another wants lifetime=15.minutes, then |
18 | # the right thing to do is to always use lifetime=15.minutes, no |
19 | # matter which order they're called in. |
20 | return if @lifetime[:time] and @lifetime[:time] < seconds |
21 | @lifetime[:time] = seconds |
22 | end |
23 | |
24 | def initialize |
25 | @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], [] |
26 | @lifetime = Hash.new |
27 | end |
28 | end |
29 | |
30 | module Caching |
31 | module ActionParams |
32 | def self.append_features(base) #:nodoc: |
33 | super |
34 | base.extend(ClassMethods) |
35 | base.send(:attr_accessor, :rendered_action_cache) |
36 | end |
37 | |
38 | module ClassMethods #:nodoc: |
39 | def caches_action_with_params(*actions) |
40 | return unless perform_caching |
41 | around_filter(ActionParamCacheFilter.new(*actions)) |
42 | end |
43 | end |
44 | |
45 | def expire_action_with_params(options = {}) |
46 | return unless perform_caching |
47 | |
48 | if options == {} |
49 | expire_meta_fragment(%r{ACTION_PARAM/.*}) |
50 | else |
51 | controller = options[:controller] || '[^/]+' |
52 | action = options[:action] || '[^/]+' |
53 | keys = (options.reject {|k,v| v.blank?}.keys-[:controller,:action]).sort_by {|k| k.to_s} |
54 | param_string = keys.collect { |key| "#{key.to_s}=#{controller.params[key]}"}.join('.*') |
55 | expire_meta_fragment(%r{ACTION_PARAM/[^/]+/#{controller}/#{action}/#{param_string}}) |
56 | end |
57 | end |
58 | |
59 | class ActionParamCacheFilter #:nodoc: |
60 | def initialize(*actions) |
61 | @actions = actions |
62 | end |
63 | |
64 | def cache_key(controller) |
65 | hostname = controller.request.host_with_port |
66 | keys = (controller.params.reject {|k,v| v.blank?}.keys-['controller','action']).sort |
67 | param_string = keys.collect { |key| "#{key.to_s}=#{controller.params[key]}"}.join('&') |
68 | "ACTION_PARAM/#{hostname}/#{controller.controller_name}/#{controller.action_name}/#{param_string}" |
69 | end |
70 | |
71 | def before(controller) |
72 | return unless @actions.include?(controller.action_name.intern) |
73 | meta, cache = controller.read_meta_fragment_expire(cache_key(controller)) |
74 | if cache |
75 | # 304 handling from Tom Fakes, |
76 | # http://craz8.com/svn/trunk/plugins/action_cache/lib/action_cache.rb |
77 | request_time = Time.rfc2822(controller.request.env["HTTP_IF_MODIFIED_SINCE"]).utc rescue nil |
78 | cached_time = meta[:cached_at] rescue nil |
79 | controller.response.headers['Cache-Control'] = 'max-age=1' |
80 | controller.response.headers['Last-Modified'] = meta[:cached_at].httpdate rescue nil |
81 | |
82 | if request_time and cached_time <= (request_time + 1) |
83 | controller.render(:text => "", :status => 304) |
84 | else |
85 | controller.render(:text => cache) |
86 | end |
87 | |
88 | controller.rendered_action_cache = true |
89 | return false |
90 | else |
91 | return true |
92 | end |
93 | end |
94 | |
95 | def after(controller) |
96 | return true if not @actions.include?(controller.action_name.intern) || controller.rendered_action_cache |
97 | return true if controller.response.headers['Status'] != "200 OK" # without this, we cache errors. grr |
98 | |
99 | meta = Hash.new |
100 | if controller.response.lifetime |
101 | meta[:expires] = Time.now + controller.response.lifetime |
102 | end |
103 | meta[:cached_at] = Time.now.utc |
104 | controller.response.headers['Cache-Control'] = 'max-age=1' |
105 | controller.response.headers['Last-Modified'] = meta[:cached_at].httpdate |
106 | controller.write_meta_fragment(cache_key(controller), meta, controller.response.body) |
107 | end |
108 | end |
109 | end |
110 | end |
111 | end |
112 | |
113 | ActionController::Caching::ActionParams.append_features(ActionController::Base) |