1. Go to this page and download the library: Download foxws/laravel-modelcache 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/ */
foxws / laravel-modelcache example snippets
use Foxws\ModelCache\Concerns\InteractsWithModelCache;
use Illuminate\Database\Eloquent\Model;
class Video extends Model
{
use InteractsWithModelCache;
}
Video::first()->modelCache('currentTime', 20);
Video::first()->modelCache('randomSeed', 20, now()->addDay()); // cache for one day
Video::first()->modelCached('currentTime');
Video::first()->modelCached('randomSeed', $default); // with fallback
use Foxws\ModelCache\Concerns\InteractsWithModelCache;
use Illuminate\Database\Eloquent\Model;
class Video extends Model
{
use InteractsWithModelCache;
/**
* @doc When using a overule, it doesn't create a separated cache by default for authenticated users.
*/
protected function cacheNameSuffix(string $key): string
{
return "{$key}:my-modelcache-prefix";
}
}