Patches: Browse | Submit New | Admin

[#9066] Calling Cache.get with optional block returns nil instead of newly cached object

Date:
2007-03-05 21:14
Priority:
3
Submitted By:
Wesley Gamble (weyus)
Assigned To:
Eric Hodel (drbrain)
Category:
None
State:
Open
Summary:
Calling Cache.get with optional block returns nil instead of newly cached object

Detailed description
In the class level get method for Cache, an optional block is invoked if the requested key is not found in the cache.
However, nil is returned to the caller instead of the requested object.

For example, in the following code:

  x = Cache.get('mykey') { 'new value' }

The cache will store 'new value' as the value for the key 'mykey', but x will get the value nil instead of 'new value'.
This would force another call to Cache.get just to retrieve the newly stored 'new value'.

Simply adding "return value" into the if block that causes the cache to be populated with the new data would
allow x to receive the new value after it was stored in the cache.

The attached patch implements this functionality.

Wes Gamble

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
memcache_util.diff Diff of memcache_util.rb Download

Changes:

Field Old Value Date By
assigned_tonone2007-03-05 21:21weyus
File Added1543: memcache_util.diff2007-03-05 21:14weyus