PHP code example of webdeva / query-cache

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

    

webdeva / query-cache example snippets


namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Webdeva\QueryCache\Traits\QueryCacheable;

class Post extends Model
{
    use QueryCacheable;
}

$posts = Post::query()->cacheQuery();

Post::flushQueryCache(['some-cache-tags']);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Webdeva\QueryCache\Traits\QueryCacheable;

class Post extends Model
{
    use QueryCacheable;

    // Custom cache duration (e.g., 2 hours)
    public $cacheFor = 7200;
}

$filteredPosts = Post::where('status', 'published')->cacheQuery();

Post::flushQueryCache(['posts', 'published']);