PHP code example of gnahotelsolutions / laravel-query-cache
1. Go to this page and download the library: Download gnahotelsolutions/laravel-query-cache 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/ */
gnahotelsolutions / laravel-query-cache example snippets
// Get 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.
User::first()->remember(60 * 60 * 24)->posts()->get();
namespace App;
use GNAHotelSolutions\LaravelQueryCache\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();