starterleague/portal_client — pull request #2 by dgiunta (2013-04-03 00:48:36+00:00)
Title: daveg: adding an initial caching implementation to the portal_client

So, this is what I've got going on here. I think it's an okay start, but the one thing I'm a little unsure of right now is the expiration bits. I would really like to make the expiration time variable based on the results. Like, if the results are for the current_quarter, then set the expiration time a tad lower than 1.day, but if the results are from a quarter previous to the current_quarter, set the expiration time much higher (like, 1.month or 1.year or something).

I couldn't see a way to do the cache.fetch without knowing the expiration date yet. It'd be kind of awesome if the expires_in key would take a lambda, to which it would yield the results of the block before actually storing the cache... but unfortunately, ActiveSupport does not look like it would be particularly easy to patch in a way to support such a change.

The other way is to not use the fetch method, but rather perform a read and a write successively / manually once we get the data back from the API. Which might not be a terrible way to go, honestly. Thoughts?