torino's avatar

Cache remember for minutes (not seconds)

According to the documentation, cache will be remembered for $seconds.

However, the value passed seems to be in minutes, not seconds.

  • add
  • remember
  • put

wrong:

Cache::put('key', 'value', $seconds);

while I believe, this would be correct:

Cache::put('key', 'value', $minutes);

or

Cache::put('key', 'value', now()->addSeconds(60));
Cache::put('key', 'value', now()->addMinutes(60));

Env: Windows, PHP 7.3

Feedback appreciated.

0 likes
3 replies
Nakov's avatar

I am trying to understand what's your point here. The documentation clearly states that for what you say it is wrong, it is really true.

So you either put the number of seconds as an integer value, or if you don't, and you use now() helper, that does not returns an int value, but a DateTime.

Instead of passing the number of seconds as an integer, you may also pass a DateTime instance representing the expiration time of the cached item.

https://laravel.com/docs/master/cache#storing-items-in-the-cache

GeordieJackson's avatar

Which version of Laravel are you using?

The setting used to be in minutes but it changed to seconds in version 5.8 (or thereabouts).

1 like
torino's avatar

@nakov my point was, that the documentatin states seconds, while "expecting minutes".

@geordiejackson thats it. That project should be brought up to date. I don't know why I didn't think on checking the docs for the version which coresponds to my installation. Thank you for pointing that out.

Please or to participate in this conversation.