class ActionView::Resolver::Cache

:nodoc:
Threadsafe template cache

def cache(key, name, prefix, partial, locals)

Cache the templates returned by the block
def cache(key, name, prefix, partial, locals)
  if Resolver.caching?
    @data[key][name][prefix][partial][locals] ||= canonical_no_templates(yield)
  else
    fresh_templates  = yield
    cached_templates = @data[key][name][prefix][partial][locals]
    if templates_have_changed?(cached_templates, fresh_templates)
      @data[key][name][prefix][partial][locals] = canonical_no_templates(fresh_templates)
    else
      cached_templates || NO_TEMPLATES
    end
  end
end

def canonical_no_templates(templates)

def canonical_no_templates(templates)
  templates.empty? ? NO_TEMPLATES : templates
end

def clear

def clear
  @data.clear
end

def initialize

def initialize
  @data = SmallCache.new(&KEY_BLOCK)
end

def templates_have_changed?(cached_templates, fresh_templates)

def templates_have_changed?(cached_templates, fresh_templates)
  # if either the old or new template list is empty, we don't need to (and can't)
  # compare modification times, and instead just check whether the lists are different
  if cached_templates.blank? || fresh_templates.blank?
    return fresh_templates.blank? != cached_templates.blank?
  end
  cached_templates_max_updated_at = cached_templates.map(&:updated_at).max
  # if a template has changed, it will be now be newer than all the cached templates
  fresh_templates.any? { |t| t.updated_at > cached_templates_max_updated_at }
end