Laravel - Cache - The Cache Helper

In addition to using the Cache facade, you may also use the global cache function to retrieve and store data via the cache. When the cache function is called with a single, string argument, it will return the value of the given key:

    $value = cache('key');

If you provide an array of key / value pairs and an expiration time to the function, it will store values in the cache for the specified duration:

    cache(['key' => 'value'], $seconds);
    cache(['key' => 'value'], now()->addMinutes(10));

When the cache function is called without any arguments, it returns an instance of the Illuminate\Contracts\Cache\Factory implementation, allowing you to call other caching methods:

    cache()->remember('users', $seconds, function () {
        return DB::table('users')->get();
When testing call to the global cache function, you may use the Cache::shouldReceive method just as if you were testing the facade.