adamcooke / json-vat

A Ruby client library for jsonvat.com
MIT License
69 stars 20 forks source link

Reset memoized rates when refreshing JSONVAT cache #7

Open wojtha opened 8 years ago

wojtha commented 8 years ago

When calling JSONVAT.cache the rates collection isn't affected as it is memoized inside the rates method and JSONVAT serves old data. I've added reset_rates which allows manual cleanup of memoized rates and it is also called from inside the cache method.

wojtha commented 8 years ago

However this won't work anyway if cache is refreshed in other process (e.g. via scheduled rake task). So some sort of cache id or lock is needed so JSONVAT in other process can see that its rates collection is outdated. The most simplistic candidate is file timestamp in case of file cache. Other candidate is the version ID but in this case the jsonvat file needs to be parsed during each check. Third candidate could be file checksum.