Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11253 (closed defect: fixed)

Opened 9 months ago

Last modified 9 months ago

[PATCH] Default value for options parameter in cache method

Reported by: remy Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: cache
Cc:

Description

def cache(key, options = nil, &block)
        if cache_configured?
          cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)

When you don't send an options argument, fetch method is called with nil for options.

def fetch(key, options = {})
        @logger_off = true
        if !options[:force] && value = read(key, options)

The fetch method set options to {} by default (it's ok), but in this case fetch was called with nil for options, so fetch try to verify if options includes :force key. But because options is nil, a "nil.[]" error is raised.

So, this patch simply set the default value for options parameter in cache method to {} instead of nil.

Like this:

def cache(key, options = {}, &block)
        if cache_configured?
          cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)

Attachments

default_value_for_options_in_cache_method_set_to_braces.diff (0.6 kB) - added by remy on 02/29/08 16:12:34.

Change History

02/29/08 16:12:34 changed by remy

  • attachment default_value_for_options_in_cache_method_set_to_braces.diff added.

03/15/08 20:02:49 changed by david

  • status changed from new to closed.
  • resolution set to fixed.

(In [9032]) Fixed that cache fetch method would cause nil exception when called with no options (closes #11253) [remy]