prismicio/ruby-kit — pull request #42 by rudyrigot (2014-06-20 23:45:50+00:00)
Title: Fix API cache invalidation

The bug came from two errors, fixed here:
* the method's signature is `get_or_set(key, value = nil, expired_in = 0)`, but during the /api endpoint caching, it was called like this: `api_cache.get_or_set(cache_key, expired_in:5) { do_something }`. This way of writing only works if the last parameter is a Hash, usually called `opt`, which isn't the case here; it isn't meant for optional parameters. [See more here](http://stackoverflow.com/questions/812058/ruby-optional-parameters). So, the value for `expired_in` was always 0, which means "cache forever".
* the first line of the method was `return get(key) if include?(key)`, which was a problem when the key existed but was expired: the method would try to run `get` on it, which would first test if it was expired, and would therefore return `nil`. The solution was to `return get(key) if include?(key) && !expired?(key)`, so that the method doesn't try to run `get`, but would skip to the next line of code, which yields, as should be.