ruby - rails caching with money gem (eu_central_bank) -


I have found this add-on for updated Mani Mani from ECB European Central Bank (updated every 24 hours)

  eu_bank || = EuCentralBank.new eu_bank.update_rates #Rails Cache.fetch ('rates',: expires_in = & gt; 24.hours) {eu_bank.update_rates} rate = eu_bank.exchange_with (money.nav (100, session [: currency]) , "USD"). To_f  

In some files there is a function to write rates ... but I'm not sure I want what I want. I am also using halokak which has a read only file system.

  eu_bank.save_rates ("/ some / file / location / exchange_rates.xml")  

I could not find any way to check the age of the object either I am thinking of the best option to load it once in 24 hours and continue for my entire rail application. Any sign?

This rail can be done using low-level caching and first_filters:

< Previous> Class ApplicationController & lt; ActionController :: Prior to Base_Filters: set_conversion_rates DR def_conversion_rates Rates = Trains. Money "eu_central_bank_rates", expires_in: 24.hours Make Money DEfault_bank.save_rates_to_s End Money.default_bank.update_rates_from_s Rates End And

This code will download rates once in 24 hours and save the result in the cache (caching module that you use), From where the Bank Object loads them on every request.


Comments