lscache icon indicating copy to clipboard operation
lscache copied to clipboard

Update readme to include fetch

Open ready4god2513 opened this issue 11 years ago • 2 comments

Often times I will want to add something to the cache only if it is not yet set. I can make this two different calls, but doing so gets a bit repetitive and unwieldy. fetch wraps the two method calls up in to a single call with a callback to run if they key is not found.

ready4god2513 avatar Nov 08 '14 00:11 ready4god2513

Interesting! Thank you for the tests and documentation. My main concern is the naming, as memcache.fetch() doesn't do that, and it wasn't obvious to me until I looked at the docs+examples. How did you come up with fetch, is that based on similar APIs that you've used? Were there any other names you considered?

pamelafox avatar Nov 08 '14 02:11 pamelafox

Hello Pamela. Yes, it is a fairly common idiom, however I definitely could see it being confusing and am completely open to a name change on that. One of the first places that I saw this process used is in Rails. Here is a little bit of information- http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-fetch

ready4god2513 avatar Nov 08 '14 05:11 ready4god2513