PHP code example of axl-media / rememberable

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

    

axl-media / rememberable example snippets


// Cache the posts for 1 hour
Post::remember(now()->addHours(1))->get();

// Cache the posts for 24 hours.
Post::remember(24 * 60 * 60)->get();

// 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 AXLMedia\Rememberable\Rememberable;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Post extends Eloquent
{
    use Rememberable;

    ...
}

// 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 ($query) {
            $query->remember(60 * 60);
        }
    ])->remember(60 * 60)->take(5)->get();

User::flushCache('user_queries');

User::flushCache();

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