DEV Community

marius-ciclistu
marius-ciclistu

Posted on • Originally published at marius-ciclistu.Medium on

Cache::touch in Maravel-Framework 10.66


Maravel-Framework

Port Laravel pull request 55954 for Cache::touch but:

  • without the get which was the whole point of this new method implementation and with all corner cases covered.
  • without any breaking change because the interfaces received @methoddockblocks
  • with typed parameter method definition.

The documentation was updated:

Extending Items TTL in the Cache

You may adjust the time to live of a cache key without retrieving its underlying value when using the memcached, dynamodb, redis, and database drivers. In other stores, the value is retrieved and then overwritten with the new expiration time.

Cache::touch(string $key, \DateTimeInterface|\DateInterval|int|null $ttl = null)

Cache::touch('key', null); // Retain forever

Cache::touch('key', 50); // Expires in 50 seconds from now
Enter fullscreen mode Exit fullscreen mode

[!WARNING]

Passing a
0 TTL will explicitly remove the cache key from the store!

Top comments (0)