1. Go to this page and download the library: Download mtgofa/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/ */
mtgofa / laravel-query-cache example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
use MTGofa\QueryCache\Traits\QueryCachable;
class User extends Model
{
use QueryCachable;
}
// config('perfectly-cache.(name)')
// Eq: config('perfectly-cache.enabled')
return [
"enabled" => true, // Is cache enabled? cache for production --> !env('APP_DEBUG', false)
"minutes" => 1, // Cache minutes.
/**
* If this event is triggered on this model,
* the cache of that table is deleted.
*/
"clear_events" => [
"created",
"updated",
"deleted",
"restored"
],
];
/**
* Thanks to the ^ sign, you can prevent your relationships from being cached.
*/
$results = Category::select("id", "name")->with([
"^_list_category_tags:id,category_id,name,slug"
])->find($id);
/**
* It will no longer be hidden in the cache for the tag table of the categories.
*/
namespace App;
class Category extends BaseModel
{
/* Cache disabled by this variable */
protected $isCacheEnable = false;
}
namespace App;
class Module extends BaseModel
{
protected $table = "modules";
protected $cacheMinutes = 20; // Now cache time 20 minutes.
}