varunazad/laravel-query-cache

Automatic query caching for Laravel with intelligent invalidation

Maintainers

Package info

github.com/varunazad/laravel-query-cache

pkg:composer/varunazad/laravel-query-cache

Statistics

Installs: 17

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2025-07-31 07:04 UTC

This package is auto-updated.

Last update: 2026-03-30 14:27:48 UTC


README

Laravel Query Cache

Blazing-fast query optimization for Laravel

✅ Supported Versions

  • Laravel: 8.x, 9.x, 10.x
  • PHP: 7.4+, 8.0+

🚀 Features

  • ⚡ Automatic caching of Eloquent queries
  • 💾 Configurable cache durations
  • 📈 Tag-based cache invalidation
  • 🔄 Support for all Laravel cache drivers
  • 📊 Minimal configuration required
  • 🔍 Works with existing Laravel applications
  • 🧮 Query Cachin with pagination

🚀 Configuration-

Publish the configuration file:

php artisan vendor:publish --provider="VarunAzad\LaravelQueryCache\QueryCacheServiceProvider" --tag="config"


**This will create config/query-cache.php with the following options:**
return [
'default_ttl' => 3600, // Default cache time in seconds
'enabled' => env('QUERY_CACHE_ENABLED', true),
'prefix' => 'query_cache_',
'store' => env('QUERY_CACHE_STORE', null),
];

Basic Uses Caching Queries use Varunazad\QueryCache\Facades\QueryCache; in you controller / Cache a query for 60 minutes $users = User::cache(60)->where('active', true)->get();

// Use default cache time from config
$posts = Post::cache()->with('comments')->get();

Pagination query add this trait in the model use Varunazad\QueryCache\Traits\Cacheable; use Cacheable;

    $users = User::with('wallet')->where('status',1)->withCachePaginate(2,60);
    return response()->json($users);

📦 Installation

composer require varunazad/laravel-query-cache
---