Cache::remember
, Cache::flexible
and Cache::forget
methods, to learn more about the available methods, check the Laravel Cache Documentation.
Cache::remember
Cache::remember
method retrieves the value of a key from the cache. If the key does not exist in the cache, the method will execute the given closure and store the result in the cache for the specified duration.
Cache::flexible
Cache::flexible
, is a caching strategy that balances performance and data freshness by defining two time periods: a “fresh” period where cached data is served immediately, and a “stale” period where outdated data is served while triggering a background refresh. When data is accessed during the stale period (in this example, between 5 and 10 seconds), users still get a fast response with slightly outdated data while the cache refreshes asynchronously, only forcing users to wait for a full recalculation if the data is accessed after both periods have expired.
Cache::forget
Cache::forget
method removes the specified key from the cache: