Skip to content

Commit 7a45d6b

Browse files
committed
versions were added.
1 parent 6c48c98 commit 7a45d6b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class ListsController < ApplicationController
9494

9595
# custom cache path with a proc
9696
caches_action :history, cache_path: -> { request.domain }
97+
98+
caches_action :show, version: -> { @list.cache_version }
9799

98100
# custom cache path with a symbol
99101
caches_action :feed, cache_path: :user_cache_path

lib/action_controller/caching/actions.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def caches_action(*actions)
111111
options = actions.extract_options!
112112
options[:layout] = true unless options.key?(:layout)
113113
filter_options = options.extract!(:if, :unless).merge(only: actions)
114-
cache_options = options.extract!(:layout, :cache_path).merge(store_options: options)
114+
cache_options = options.extract!(:layout, :cache_path, :version).merge(store_options: options)
115115

116116
around_action ActionCacheFilter.new(cache_options), filter_options
117117
end
@@ -147,15 +147,18 @@ def expire_action(options = {})
147147

148148
class ActionCacheFilter # :nodoc:
149149
def initialize(options, &block)
150-
@cache_path, @store_options, @cache_layout =
151-
options.values_at(:cache_path, :store_options, :layout)
150+
@cache_path, @store_options, @cache_layout, @version =
151+
options.values_at(:cache_path, :store_options, :layout, :version)
152152
end
153153

154154
def around(controller)
155155
cache_layout = expand_option(controller, @cache_layout)
156156
path_options = expand_option(controller, @cache_path)
157+
version = expand_option(controller, @version)
157158
cache_path = ActionCachePath.new(controller, path_options || {})
158159

160+
@store_options.merge!(version: version)
161+
159162
body = controller.read_fragment(cache_path.path, @store_options)
160163

161164
unless body

0 commit comments

Comments
 (0)