ArtisanTinkerer.github.io

Blog

View on GitHub

Accessing

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

### Passing a Closure

It it does not exist, get from Cache.

 $value = Cache::get('key', function () {
    return DB::table(...)->get();
});

### Checking for Existence

 if (Cache::has('key')) {
    //
}

### Incrementing / Decrementing Values

## Storing

 Cache::put('key', 'value', $minutes);

### Store if not present

 Cache::add('key', 'value', $minutes);

Retrieve and Store

I think I will use this a lot.

$value = Cache::remember('users', $minutes, function () {
    return DB::table('users')->get();
});

Retrieve and Delete

Storing Items Forever

Removing

Cache::forget('key');

Clearing all cache

Cache::flush();

The Cache Helper

$value = cache('key');
cache(['key' => 'value'], $minutes);


Cache Tags

Cache tags are not supported when using the file or database cache

Events

I could use an event to invalidate?