I want to set a value to an existing cache. I have something like this:
Cache::put('key',['foo', 'bar'], $expiresAt);
Now how can I push 'sad'
value to this key without deleting last values?
Need something like this after pushing value and getting cache:
{'foo', 'bar', 'sad'}
Laravel provides a unified API for various caching systems. The cache configuration is located at app/config/cache. php . In this file you may specify which cache driver you would like used by default throughout your application.
To enable Laravel caching services, first use the Illuminate\Contracts\Cache\Factory and Illuminate\Contracts\Cache\Repository, as they provide access to the Laravel caching services. The Factory contract gives access to all the cache drivers of your application.
By default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects on the server's filesystem. For larger applications, it is recommended that you use a more robust driver such as Memcached or Redis. You may even configure multiple cache configurations for the same driver.
Adding caching to Laravel. Memcache is an in-memory, distributed cache. Its primary API consists of two operations: SET(key, value) and GET(key) . Memcache is like a hashmap (or dictionary) that is spread across multiple servers, where operations are still performed in constant time.
Try the following:
Cache::put('key',['foo', 'bar'], $expiresAt);
$key = Cache::get('key');
$key[] = 'sad';
Cache::put('key', $key, $expiresAt);
Just get the existing cache, update it and put it back again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With