currency-converter-php icon indicating copy to clipboard operation
currency-converter-php copied to clipboard

Cache is never used unless specified in seconds

Open lauri-elevant opened this issue 6 years ago • 0 comments

The docs state that you should set cache timeout like so:

$cacheAdapter->setCacheTimeout(\DateInterval::createFromDateString('123 second'));

Which is correct, but potentially misleading since if you do that:

$cacheAdapter->setCacheTimeout(\DateInterval::createFromDateString('2 day'));

.. the c ache is never used, since the DateInterval is not correctly used to compare the elapsed time, but just formatted as seconds. A 2-day interval will emit "0" when ->format('%s') is called since it does not internally perform the date calculations, but is just a structure to hold the date/month/hour/whatever values.

    Note:

    The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. This is expected because it is not possible to overflow values like "32 days" which could be interpreted as anything from "1 month and 4 days" to "1 month and 1 day".

lauri-elevant avatar Jan 28 '19 12:01 lauri-elevant