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 |