In an app powered by Symfony 1.4, I would like to cache the response
from an ECB (European Central Bank) web service which provides currency
exchange rates [1]. While the web service generally responds very fast,
recently there have been outages lasting for hours.
The cache may work as follows:
* A timeout is set to, say, ten minutes.
* When loading the (Symfony powered) web page:
- Before the timeout has been hit: Exchange rates are read from
the cache.
- After the timeout has been hit: The ECB web service is queried.
If the ECB doesn't reply, then old data is used. Otherwise, the
cache is refreshed with updated data. In any case, the timeout
is extended.
* When deploying, then the cache is emptied (part of the documented
deployment process). This ensures that, if the ECB stops responding
completely, then someone will become aware of it eventually. Of
course, one could set up a system where an email is sent once the
ECB hasn't responded for a day or so, but that seems overkill for
the site in question.
Now, I could either store the cached data (currency exchange rates) in a
MySQL database, or I could use Cache_Lite [2], or:
Is there a specific Symfony way to do this? How would you do it?
Well I prefer this way: inside model which return bank query use
If($value = $memcache->get('key')){
$value = $superModel->queryBank();
$memcache->set('key', $value);
}
I don't remember how setup timeout, but memcache extension support timeout.
Отправлено с беспроводного устройства BlackBerry®
-----Original Message-----
From: "Felix E. Klee" <felix.k...@inka.de>
Sender: symfony1@googlegroups.com
Date: Mon, 1 Oct 2012 22:13:11 To: <symfony1@googlegroups.com>
Reply-To: symfony1@googlegroups.com
Subject: [symfony1] Caching a web query?
In an app powered by Symfony 1.4, I would like to cache the response
from an ECB (European Central Bank) web service which provides currency
exchange rates [1]. While the web service generally responds very fast,
recently there have been outages lasting for hours.
The cache may work as follows:
* A timeout is set to, say, ten minutes.
* When loading the (Symfony powered) web page:
- Before the timeout has been hit: Exchange rates are read from
the cache.
- After the timeout has been hit: The ECB web service is queried.
If the ECB doesn't reply, then old data is used. Otherwise, the
cache is refreshed with updated data. In any case, the timeout
is extended.
* When deploying, then the cache is emptied (part of the documented
deployment process). This ensures that, if the ECB stops responding
completely, then someone will become aware of it eventually. Of
course, one could set up a system where an email is sent once the
ECB hasn't responded for a day or so, but that seems overkill for
the site in question.
Now, I could either store the cached data (currency exchange rates) in a
MySQL database, or I could use Cache_Lite [2], or:
Is there a specific Symfony way to do this? How would you do it?
-- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony1" group.
To post to this group, send email to symfony1@googlegroups.com
To unsubscribe from this group, send email to
symfony1+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony1?hl=en
Best thing to use is symfony's caching classes that tie into memory caches
such as APC, EAccelerator or Memcache. Personally I would recommend APC as
this has been more fully integrated into PHP. Also, memcaching is ideal for
your use case because it is transitory data. Storing temporary data in a
database should be avoided as much as possible usually.
On Tue, Oct 2, 2012 at 7:51 AM, Кирилл <bestestm...@gmail.com> wrote:
> Well I prefer this way: inside model which return bank query use
> If($value = $memcache->get('key')){
> $value = $superModel->queryBank();
> $memcache->set('key', $value);
> }
> I don't remember how setup timeout, but memcache extension support timeout.
> Отправлено с беспроводного устройства BlackBerry(R)
> -----Original Message-----
> From: "Felix E. Klee" <felix.k...@inka.de>
> Sender: symfony1@googlegroups.com
> Date: Mon, 1 Oct 2012 22:13:11
> To: <symfony1@googlegroups.com>
> Reply-To: symfony1@googlegroups.com
> Subject: [symfony1] Caching a web query?
> In an app powered by Symfony 1.4, I would like to cache the response
> from an ECB (European Central Bank) web service which provides currency
> exchange rates [1]. While the web service generally responds very fast,
> recently there have been outages lasting for hours.
> The cache may work as follows:
> * A timeout is set to, say, ten minutes.
> * When loading the (Symfony powered) web page:
> - Before the timeout has been hit: Exchange rates are read from
> the cache.
> - After the timeout has been hit: The ECB web service is queried.
> If the ECB doesn't reply, then old data is used. Otherwise, the
> cache is refreshed with updated data. In any case, the timeout
> is extended.
> * When deploying, then the cache is emptied (part of the documented
> deployment process). This ensures that, if the ECB stops responding
> completely, then someone will become aware of it eventually. Of
> course, one could set up a system where an email is sent once the
> ECB hasn't responded for a day or so, but that seems overkill for
> the site in question.
> Now, I could either store the cached data (currency exchange rates) in a
> MySQL database, or I could use Cache_Lite [2], or:
> Is there a specific Symfony way to do this? How would you do it?
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
> You received this message because you are subscribed to the Google
> Groups "symfony1" group.
> To post to this group, send email to symfony1@googlegroups.com
> To unsubscribe from this group, send email to
> symfony1+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony1?hl=en
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
> You received this message because you are subscribed to the Google
> Groups "symfony1" group.
> To post to this group, send email to symfony1@googlegroups.com
> To unsubscribe from this group, send email to
> symfony1+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony1?hl=en
On Tue, Oct 2, 2012 at 8:24 AM, Gareth McCumskey <gmccums...@gmail.com>
wrote:
> Best thing to use is symfony's caching classes that tie into memory
> caches such as APC, EAccelerator or Memcache.
Thanks for the suggestion. However, caching to memory has one major
disadvantage:
Suppose the server was restarted, and I discover that - out of bad luck
- the ECB webservice is not available currently. Then there would be no
backup of the last response.
> Storing temporary data in a database should be avoided as much as
> possible usually.
While, for various reasons, I also don't really want to use the database
here, I don't think using it would have any performance impact. After
all, when a page is loaded, there are various database queries anyhow.
The database is fast. It is used for real-time autocompletion on the
web-site, for example.
Sorry, this is BS - the timeout would never be hit. Correction:
if ($cache->timeoutReached()) {
if ($newRates = queryBank()) {
$cache->set('rates', $newRates);
} // else: outage =keep old data
$cache->setTimeoutFromNow(600);
}
$rates = $cache->get('rates');
Any idea what caching system to use for the given purpose?
Quick thought: I could keep the timeout expiration time in memcache (or
APC, or whatever), and then just use standard PHP file funcitons to
read/write the file containing the rates. Memcache is necessary to share
the timeout expiration time among several processes.
Eventually, I used `sfFileCache`, but with custom expiration system
(standard lifetime set to `PHP_INT_MAX`): The custom system avoids
clearing of the expired cache when the ECB server doesn't respond. For
the given application, slightly outdated data is better than no data.