I have added the Currency Exchange module to my site and have the exchange rate appear on the main pages. It works great...thanks for developing it.

I would like to be able to cache the results from Yahoo finance so that each time a page is opened, the module doesn't reconnect to get the data. Is there any way to cache it, similar to what's done with the aggregator module?

Also, I've tried to deselect the option to Log all currency conversions and errors to watchdog, but it doesn't seem to change anything. Each time I return to the currency_api settings the option to log to watchdog is selected. How can I make this change stick?

Comments

kbahey’s picture

It requires programming to do it the way you want.

Look at the stock module, and how I made it work with the caching stock api, and you can do something similar. But it has to cache pairs (FROM/TO), not just one single symbol like stock does.

januario’s picture

For now, I've taken care of the logging to watchdog problem by removing the line ~132

_log_to_watchdog("currency: $amount $from = $value $to", WATCHDOG_NOTICE);

So far, it seems to be working well and is helping with the problem of this module flooding my watchdog.

As for the caching, it seems be more difficult that I can handle right now.

Thanks for the great module and incredibly fast response.

Victor

wim leers’s picture

Version: 4.6.x-1.x-dev » 5.x-1.x-dev
Assigned: Unassigned » wim leers

I will probably be using this module soon and caching would definitely be required. When I get to using it, I'll submit a patch.

murz’s picture

Subscribe.

It will be good to cache exchange rates in DB and cache used rates in memory.
For example, I developing exchange module uc_currency for Ubercart. And when Ubercart displays page with many products, each price must be converted from one currency to another. And usually currency pair for all products is equal.

johnhanley’s picture

I successfully implemented a database cache in currency_api.module back in December. It works great and the modification is very light (2153 additional bytes, including comments). It only requires one additional table (consisting of 4 columns: currency_from, currency_to, rate, timestamp), which is automatically created by the included currency_api.install script. Cron is not required to purge out-of-date data. The cache time is adjustable or can be disabled via an admin page. I'm overdue to upload the patch. I will try and do this soon.

wim leers’s picture

Assigned: wim leers » Unassigned

I didn't need this feature yet, which is why I didn't implement it yet. I did work on some other features, because of which I became co-maintainer. So, I can guarantee you that your patch will get in ASAP if you post it :)

2222a’s picture

Cache-ing /storing would be amazing. One can even do graphs of how the currency went say from last month to now given that all is entered in the database when a user searches. I will patiently wait bacteria man for your patch

johnhanley’s picture

Hi all,

I'm headed out of town tomorrow and will be gone for six days, but I promise to post the patch upon my return. Incidentally the cache is two-tiered. Once cached locally the first load comes from the database, but subsequent requests come from a static variable (just like the way user_access() works.) Anyway, thanks for your patience.

Cheers,
John (aka. bacteria man)

johnhanley’s picture

StatusFileSize
new7.1 KB
new37.65 KB

Hi all,

Here, at long last, is the currency_api cache modification.

Attached are two files: a patch version and a zip file containing the full revised module and new install file.

I've been using this locally on my dev server for a couple of months with zero problems. That said, please let me know if you find anything.

Thanks,
John

----------------------------------------

Here's a list of changes:

functions modified:

currency_api_convert() -- logic to check for cached rate; update cache
currency_api_admin_settings() -- added form element to select/save cache interval
currency_api_get_desc() -- optimized: replaced key existence loop check with isset()

functions created:

currency_api_load() -- fetch cache data, if exists. First check static variable, then database
currency_api_save() -- delete old entry (if exists, based on expiration setting), cache the data

database table created:

currencyapi: currency_from, currency_to, rate, timestamp

files created:

currency_api.install -- hooks to create and delete currencyapi table

kbahey’s picture

Status: Active » Needs work

Thanks for the patch.

The patch is too big, and this is mainly due to it having DOS line endings.

Can you please provide the patch in the format specified here: http://drupal.org/patch so it is easier to review?

Thanks.

splash112’s picture

Perfect! Works like a charm!

kbahey’s picture

Version: 5.x-1.x-dev » 5.x-1.1-beta1

Committed.

Thanks

kbahey’s picture

Status: Needs work » Fixed
johnhanley’s picture

kbahey, sorry about the patch size. I intended to upload a revised version, but my on-going professional and personal commitments have prevented me from doing any side stuff lately. Luckily it appears that splash112 was able to make the first one work and confirmed it works as advertised.

Thanks for the great module.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.