Download the PHP package yonkosam/laravel-cached-pagination without Composer
On this page you can find all versions of the php package yonkosam/laravel-cached-pagination. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yonkosam/laravel-cached-pagination
More information about yonkosam/laravel-cached-pagination
Files in yonkosam/laravel-cached-pagination
Package laravel-cached-pagination
Short Description A simple, tag-based caching layer for Eloquent pagination.
License MIT
Homepage https://github.com/yonkosam/laravel-cached-pagination
Informations about the package laravel-cached-pagination
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.
โจ 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
You can install the package via Composer:
Publish Configuration (Optional)
You can publish the config file with:
This is the contents of the published config file:
๐ Quick Start
1. Add the Trait to Your Model
2. Use Cached Pagination in Your Controllers
๐ Usage
Basic Cached Pagination
Replace Laravel's standard paginate() method with cachedPaginate():
Custom Cache Duration
Specify a custom TTL (Time To Live) in seconds:
Simple Pagination with Cache
For simple pagination (Previous/Next only):
Cursor Pagination with Cache
For cursor-based pagination:
Complex Queries
The package works with any Eloquent query:
Manual Cache Management
Clear cache for a specific model:
โ๏ธ Configuration
Cache Store Requirements
This package requires a cache store that supports tagging. The following Laravel cache drivers support tags:
- โ Redis (Recommended)
- โ Memcached
- โ Array (for testing)
- โ File (not supported)
- โ Database (not supported)
Automatic Cache Invalidation
Configure when the cache should be automatically cleared:
Performance Considerations
- TTL Selection: Choose appropriate cache durations based on your data update frequency
- Memory Usage: Monitor Redis/Memcached memory usage with heavy pagination caching
- Cache Warming: Consider implementing cache warming strategies for frequently accessed pages
๐ง Advanced Usage
Custom Cache Keys
The package automatically generates unique cache keys based on:
- Model table name
- Query SQL and bindings
- Pagination parameters
- Page number
Cache keys follow this pattern:
Working with Views
In your Blade templates, use cached pagination results exactly like regular pagination:
API Resources
๐งช Testing
Run the tests with:
Run tests with coverage:
Run static analysis:
๐ Performance Benchmarks
Performance improvements vary based on query complexity and data size:
| Scenario | Without Cache | With Cache | Improvement |
|---|---|---|---|
| Simple pagination (1000 records) | ~50ms | ~2ms | 96% faster |
| Complex joins (10,000 records) | ~200ms | ~3ms | 98.5% faster |
| Heavy aggregations | ~500ms | ~2ms | 99.6% faster |
Benchmarks performed on a typical LAMP stack with Redis cache
โ FAQ
Q: What happens if my cache store doesn't support tags?
A: The package gracefully falls back to regular pagination without caching. No errors will occur.
Q: How do I cache pagination for API endpoints?
A: Use the same methods in your API controllers. The package works seamlessly with API resources and JSON responses.
Q: Can I use this with custom pagination views?
A: Yes! The cached pagination results work exactly like Laravel's default pagination, so custom views will work without modification.
Q: Will this work with Livewire/Alpine.js?
A: Absolutely! The pagination links and AJAX requests will work normally since the underlying pagination structure is unchanged.
Q: How do I debug cache issues?
A: Enable Laravel's query log to see if queries are being cached:
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING for details.
Development Setup
- Clone the repository
- Install dependencies:
composer install - Run tests:
composer test - Check code style:
composer format
๐ Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
๐ Changelog
Please see CHANGELOG for more information on what has changed recently.
๐ฅ Credits
- Abdellatif Samlani - Creator and maintainer
- All Contributors - Thank you for your contributions!
๐ License
The MIT License (MIT). Please see License File for more information.
โญ If this package helped you, please give it a star on GitHub!
All versions of laravel-cached-pagination with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0