Caching is a strategy that aims to get a higher performance of an application. Here are some experiences that I have learned during working on Laravel.
Different storage drives must be used in particular situations
Laravel provides file storage as default and it has a convenient way to implement other kinds of storages, such as Memcached, and Redis. You can specify which store driver you want to use by using the store method.
Please keep in mind, if you are using the cache like this below, Larevel will choose file storage as default.
"$value = Cache::get('key');"
As it mentioned in Laravel documentary, "Cache tags are not supported when using the file or database cache drivers.". This is very important when you are trying to purge plenty of items in your cache. Since it's not a good practice to purge your cache items one by one. Your only choice is to flush the file cache with purging all items.
Here may raise issues. Some other cache items which you may not want to purge will be purge either. So you should use different types of cache in different scenarios by using different cache stores or by using tags.
Cache service must be replaceable
In my current project, I’m caching third-party API responses to improve the server response time for clients. Just assume that the cache is not working. What’s the best plan to deal with this situation? For me, I have set up a strategy to request third-party API and return to clients directly without caching if the cache is not working. I’m also using another cache policy that caching the response permanent and updating the cache content periodically. The cache will be always working, even the third-party API is down sometimes.
Don't forget to add a button to clear all cache
The CLEAR ALL button on a website is as important as the nuclear button in the real world. Make sure you have the capability to destroy all caches at an emergency situation. I'm sure about you will thank me in the future.