cvsouth/cache-null

Enables support for caching of null values in Laravel

1.0.5 2022-02-01 16:53 UTC

This package is auto-updated.

Last update: 2024-04-29 04:13:38 UTC


README

By default in Laravel, as per PSR-16, cached null values are inistingustable from a cache miss:

A cache miss will return null and therefore detecting if one stored null is not possible.
Cache::forever('test1a', null);
$exists = Cache::has('test1a'); // returns FALSE

$value = Cache::rememberForever('test1b', function() {
    print('calculating');
    return null;
}); // 'calculating' prints every single time

Install this package if you want to enable support for caching null values:

Cache::forever('test2a', null);
$exists = Cache::has('test2a'); // returns TRUE

$value = Cache::rememberForever('test2b', function() {
    print('calculating');
    return null;
}); // 'calculating' prints only the first time

Installation

composer require cvsouth/cache-null

Notices

The only cache driver currently supported by this package is redis.