Decrementing the Value of an Item in the Cache

Problem

You want to decrement a value in the cache.

Solution

Use Cache::decrement()

$value = Cache::decrement('key');

If the value of key is 10, then the first time this is called $value will be 9, the next call it will return 8, and so forth.

You can also pass a value to decrement.

$value = Cache::decrement('key', 50);

Discussion

Doesn't work with File or Database caches.

comments powered by Disqus