Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent concurrent access to template cache - closes #6404

  • Loading branch information...
commit 0242c0ae23501c34b06580aef3da17a37cf16886 1 parent 565c1b0
@pinetops authored
Showing with 21 additions and 15 deletions.
  1. +21 −15 actionpack/lib/action_view/template/resolver.rb
View
36 actionpack/lib/action_view/template/resolver.rb
@@ -2,6 +2,7 @@
require "active_support/core_ext/class"
require "active_support/core_ext/io"
require "action_view/template"
+require "thread"
module ActionView
# = Action View Resolver
@@ -34,10 +35,13 @@ class << self
def initialize
@cached = Hash.new { |h1,k1| h1[k1] = Hash.new { |h2,k2|
h2[k2] = Hash.new { |h3,k3| h3[k3] = Hash.new { |h4,k4| h4[k4] = {} } } } }
+ @cached_mutex = Mutex.new
end
def clear_cache
- @cached.clear
+ @cached_mutex.synchronize {
+ @cached.clear
+ }
end
# Normalizes the arguments and passes it on to find_template.
@@ -71,22 +75,24 @@ def cached(key, path_info, details, locals) #:nodoc:
name, prefix, partial = path_info
locals = locals.map { |x| x.to_s }.sort!
- if key && caching?
- @cached[key][name][prefix][partial][locals] ||= decorate(yield, path_info, details, locals)
- else
- fresh = decorate(yield, path_info, details, locals)
- return fresh unless key
-
- scope = @cached[key][name][prefix][partial]
- cache = scope[locals]
- mtime = cache && cache.map(&:updated_at).max
-
- if !mtime || fresh.empty? || fresh.any? { |t| t.updated_at > mtime }
- scope[locals] = fresh
+ @cached_mutex.synchronize {
+ if key && caching?
+ @cached[key][name][prefix][partial][locals] ||= decorate(yield, path_info, details, locals)
else
- cache
+ fresh = decorate(yield, path_info, details, locals)
+ return fresh unless key
+
+ scope = @cached[key][name][prefix][partial]
+ cache = scope[locals]
+ mtime = cache && cache.map(&:updated_at).max
+
+ if !mtime || fresh.empty? || fresh.any? { |t| t.updated_at > mtime }
+ scope[locals] = fresh
+ else
+ cache
+ end
end
- end
+ }
end
# Ensures all the resolver information is set in the template.
Please sign in to comment.
Something went wrong with that request. Please try again.