PHP code example of elipzis / laravel-cacheable-model

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

    

elipzis / laravel-cacheable-model example snippets


...
use ElipZis\Cacheable\Models\Traits\Cacheable;
...

class YourModel extends Model {

    use Cacheable;
    ... 

    //Default values for the Cacheable trait - Can be overridden per model
    return [
        //How long should cache last in general?
        'ttl' => 300,
        //By what should cache entries be prefixed?
        'prefix' => 'cacheable',
        //What is the identifying, unique column name?
        'identifier' => 'id',
        //Do you need logging?
        'logging' => [
            'channel' => null, //Which channel should be used?
            'enabled' => false,
            'level' => 'debug',
        ],
    ];

...
use ElipZis\Cacheable\Models\Traits\Cacheable;
...

class YourModel extends Model {

    use Cacheable;
    ... 

YourModel::query()->get();

YourModel::query()->where('field', 'test')->first();

YourModel::query()->insert([...]);

public function getCacheableProperties(): array {
    return [
        'ttl' => 300,
        'prefix' => 'cacheable',
        'identifier' => 'id',
        'logging' => [
            'channel' => 'anotherChannel',
            'enabled' => false,
            'level' => 'debug',
        ],
    ];
}

YourModel::query()->withoutCache()->get();

YourModel::query()->flushCache();
bash
php artisan vendor:publish --tag="cacheable-model-config"