PHP code example of watson / rememberable

1. Go to this page and download the library: Download watson/rememberable 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/ */

    

watson / rememberable example snippets


// Get a the first user's posts and remember them for a day.
User::first()->remember(now()->addDay())->posts()->get();

// You can also pass the number of seconds if you like (before Laravel 5.8 this will be interpreted as minutes).
User::first()->remember(60 * 60 * 24)->posts()->get();


namespace App;

use Watson\Rememberable\Rememberable;
use Illuminate\Database\Eloquent\Model as Eloquent;

abstract class Model extends Eloquent
{
    use Rememberable;
}


namespace App;

class Post extends Model
{
    //
}

// Remember the number of users for an hour.
$users = User::remember(60 * 60)->count();

// Remember the number of users for an hour and tag it with 'user_queries'
User::remember(60 * 60)->cacheTags('user_queries')->count();

// Remember the number of users for an hour and prefix the key with 'users'
User::remember(60 * 60)->prefix('users')->count();

// Remember the number of users for an hour using redis as cache driver
User::remember(60 * 60)->cacheDriver('redis')->count();

$users = User::where("id", ">", "1")
    ->with(['posts' => function ($q) { $q->remember(60 * 60); }])
    ->remember(60 * 60)
    ->take(5)
    ->get();

User::flushCache('user_queries');

User::flushCache();

User::latest()->dontRemember()->get();