PHP code example of genealabs / laravel-model-caching

1. Go to this page and download the library: Download genealabs/laravel-model-caching 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/ */

    

genealabs / laravel-model-caching example snippets


    $app->register(GeneaLabs\LaravelModelCaching\Providers\Service::class);
    

 namespace App;

use GeneaLabs\LaravelModelCaching\Traits\Cachable;

abstract class BaseModel
{
    use Cachable;
    //
}

 namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;

use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class BaseModel extends Model
{
    use Cachable;

    protected $cachePrefix = "test-prefix";
}

    'cache-prefix' => 'test-prefix',

class MyModel extends Model
{
    use Cachable;

    protected $cacheCooldownSeconds = 300; // 5 minutes

    // ...
}

(new Comment)
    ->withCacheCooldownSeconds(30) // override default cooldown seconds in model
    ->get();

(new Comment)
    ->withCacheCooldownSeconds() // use default cooldown seconds in model
    ->get();

    $result = app("model-cache")->runDisabled(function () {
        return (new MyModel)->get(); // or any other stuff you need to run with model-caching disabled
    });
    

$results = $myModel->disableCache()->where('field', $value)->get();
sh
  php artisan modelCache:publish --config
  
sh
php artisan modelCache:clear --model=App\Model