PHPackages                             yonkosam/laravel-cached-pagination - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. yonkosam/laravel-cached-pagination

ActiveLibrary[Caching](/categories/caching)

yonkosam/laravel-cached-pagination
==================================

A simple, tag-based caching layer for Eloquent pagination.

v1.0.0(10mo ago)06[2 PRs](https://github.com/YonkoSam/laravel-cached-pagination/pulls)MITPHPPHP ^8.0CI passing

Since Jun 23Pushed 1mo agoCompare

[ Source](https://github.com/YonkoSam/laravel-cached-pagination)[ Packagist](https://packagist.org/packages/yonkosam/laravel-cached-pagination)[ Docs](https://github.com/yonkosam/laravel-cached-pagination)[ GitHub Sponsors](https://github.com/yonko)[ RSS](/packages/yonkosam-laravel-cached-pagination/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (13)Versions (6)Used By (0)

Laravel Cached Pagination
=========================

[](#laravel-cached-pagination)

[![Latest Version on Packagist](https://camo.githubusercontent.com/03127f7a1330fdc9afc3d751b7dd24ad2655f327fe2bb69f44f929267b998e12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f6e6b6f73616d2f6c61726176656c2d6361636865642d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yonkosam/laravel-cached-pagination)[![GitHub Tests Action Status](https://camo.githubusercontent.com/bb8d35bb036d84c9448b5ebef65a67b387a5a3a407abfe3a1856ac6c887e0ed8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796f6e6b6f73616d2f6c61726176656c2d6361636865642d706167696e6174696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/yonkosam/laravel-cached-pagination/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/4eb0dd100bf1e74bbcc1bf25eadb7bd9cb7cda066b9955073d3024f71a96c5c7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796f6e6b6f73616d2f6c61726176656c2d6361636865642d706167696e6174696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/yonkosam/laravel-cached-pagination/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/154cdb4166357e7a40bca593cd00d66db1f489e5b1e9689348f17adf005418d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796f6e6b6f73616d2f6c61726176656c2d6361636865642d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yonkosam/laravel-cached-pagination)

A simple, tag-based caching layer for Laravel Eloquent pagination that dramatically improves performance by caching paginated query results. This package extends Laravel's built-in pagination with smart caching capabilities while maintaining full compatibility with existing pagination methods.

Perfect for applications with heavy database queries where pagination results don't change frequently. The package automatically invalidates cache when models are created, updated, or deleted, ensuring data consistency.

```
// Before: Regular pagination (hits database every time)
$users = User::where('active', true)->paginate(15);

// After: Cached pagination (cached for 1 hour by default)
$users = User::where('active', true)->cachedPaginate();
```

✨ Features
----------

[](#-features)

- 🚀 **Drop-in replacement** for Laravel's pagination methods
- 🏷️ **Tag-based caching** for efficient cache invalidation
- 🔄 **Automatic cache invalidation** on model changes
- 📊 **Multiple pagination types** supported (paginate, simplePaginate, cursorPaginate)
- ⚙️ **Configurable TTL** and cache behavior
- 🧪 **Fully tested** with comprehensive test coverage
- 🔒 **Laravel 10, 11, 12** compatible

📦 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require yonkosam/laravel-cached-pagination
```

### Publish Configuration (Optional)

[](#publish-configuration-optional)

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-cached-pagination-config"
```

This is the contents of the published config file:

```
return [
    /**
     * The default Time To Live (TTL) for cached paginations in seconds.
     * You can use an integer for seconds or a \DateInterval object.
     * The default is 1 hour (3600 seconds).
     */
    'ttl' => 3600,

    /**
     * Determine whether the pagination cache should be automatically
     * cleared when a model is updated.
     */
    'clear_on_update' => true,

    /**
     * Determine whether the pagination cache should be automatically
     * cleared when a model is created.
     */
    'clear_on_create' => true,

    /**
     * Determine whether the pagination cache should be automatically
     * cleared when a model is deleted.
     */
    'clear_on_delete' => true,
];
```

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Add the Trait to Your Model

[](#1-add-the-trait-to-your-model)

```
