PHP code example of hareland / multi-cache-remember

1. Go to this page and download the library: Download hareland/multi-cache-remember library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hareland / multi-cache-remember example snippets


// in config/app.php
'providers' => [
    \Hareland\MultiCacheRemember\MultiCacheServiceProvider::class,
]



use Illuminate\Support\Facades\Cache;

[$user1, $user2, $meta] = Cache::rememberMany([
    'user:1' => fn ()=> \App\Models\User::findOrFail(1),
    'user:2' => fn ()=> \App\Models\User::findOrFail(2),
    'meta:11'=> fn ()=> \App\Models\Meta::findOrFail(11),
], 5);// 5 seconds is now the TTL for all the items.



use Illuminate\Support\Facades\Cache;

[$topStats, $orgSales, $overview] = Cache::rememberMany([
    'dashboard.stats.top:user:1' => [fn() => \App\Models\Stats::findFor(request()->user()), 60 * 15],
    'dashboard.stats.sales:org:3' => [fn() => \App\Models\StatsForOrf::findFor(request()->user()->currentOrg), 60 * 5],
    'dashboard.stats.overview:org:3' => fn() => \App\Models\OverviewStats::findFor(request()->user()->currentOrg),
], 60); // 60 seconds is the default TTL for any keys that does not have a custom one.