diff options
author | Santosh Wadghule <santosh.wadghule@gmail.com> | 2016-04-16 16:16:17 +0530 |
---|---|---|
committer | Santosh Wadghule <santosh.wadghule@gmail.com> | 2016-04-18 20:25:16 +0530 |
commit | a712acc42543b575a623e1a8880c0e9dd5505cfa (patch) | |
tree | 9867a176a8608dbbd6179ed8a09b4a97ffc64a0f /activesupport/lib | |
parent | 38d6d4129bd9a04d71b29d4c2b47419523ecff5d (diff) | |
download | rails-a712acc42543b575a623e1a8880c0e9dd5505cfa.tar.gz rails-a712acc42543b575a623e1a8880c0e9dd5505cfa.tar.bz2 rails-a712acc42543b575a623e1a8880c0e9dd5505cfa.zip |
Fix forced cache miss for fetch.
- Raised an argument error if no block is passed to #fetch with
'force: true' option is set.
- Added tests for the same.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 85f462a1b1..f27bac3dca 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -198,10 +198,16 @@ module ActiveSupport # cache.fetch('city') # => "Duckburgh" # # You may also specify additional options via the +options+ argument. - # Setting <tt>force: true</tt> will force a cache miss: + # Setting <tt>force: true</tt> will force a cache miss and return value of + # the block will be written to the cache under the given cache key. # # cache.write('today', 'Monday') - # cache.fetch('today', force: true) # => nil + # cache.fetch('today', force: true) { 'Tuesday' } # => 'Tuesday' + # + # It will raise an argument error if no block is passed to #fetch with + # option <tt>force: true</tt> is set. + # + # cache.fetch('today', force: true) # => ArgumentError: Missing block # # Setting <tt>:compress</tt> will store a large cache entry set by the call # in a compressed format. @@ -292,6 +298,8 @@ module ActiveSupport else save_block_result_to_cache(name, options) { |_name| yield _name } end + elsif options && options[:force] + raise ArgumentError, 'Missing block' else read(name, options) end |