PHP code example of authentik / eloquent-cache

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

    

authentik / eloquent-cache example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Authentik\EloquentCache\Cacheable;

class Category extends Model
{
    use Cacheable;


    /*
     * You can optionally override the following functions:
     */
    
    // Time To Live in minutes (default value: 0 => no TTL)
    public function getCacheTTL() {
        return 60;
    }

    // default value: the lowercase name of the model
    public function getCacheTagName() {
        return 'cat';
    }

    // Cache busting will automatically invalidate the cache when model instances are updated or deleted.
    // default value: true
    public function isCacheBustingEnabled() {
        return false;
    }

    // Whether or not to keep model instances in a static array cache
    //  (useful to avoid querying the cache store/building instances from json multiple times)
    // default value: true
    public function isStaticCacheEnabled() {
        return false;
    }
}

Category::find(1)->cache();

$refreshedInstance = Category::find(1)->refresh();

// or

Category::flush(Category::find(1));

Category::flush();