PHP Microservices by Sanchez Carlos Perez & Vilarino Pablo Solar

PHP Microservices by Sanchez Carlos Perez & Vilarino Pablo Solar

Author:Sanchez, Carlos Perez & Vilarino, Pablo Solar [Sanchez, Carlos Perez]
Language: eng
Format: azw3
Publisher: Packt Publishing
Published: 2017-03-29T04:00:00+00:00


Tip

The key is defined by you, so a good practice is generating a key that you can remember in order to regenerate in the future. In our example, we defined the key using L (for location) and then the latitude and longitude. However, if you are going to save an ID, it should be included as part of the key.

Working with our cache layer is easy in Lumen.

To obtain elements from the cache, you can use "get". It allows two parameters--the first one is to specify the key you want (and is required), and the second one is the value to use if the key is not stored in cache (and obviously is optional):

$value = Cache::get('key', 'default');

A similar method to store data available is Cache::forever($cacheKey, $cacheValue); this call will store the $cacheValue identified by $cacheKey in our cache layer, forever, until you delete or update it.

If you don't specify the expiration time for your stored elements, it is important to know how to remove them. In Lumen, you can do it with Cache::forget($cacheKey); if you know the $cacheKey assigned to an element. In the case of needing to remove all the elements stored in the cache, we can do this with a simple Cache::flush();.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.