Download the PHP package iperamuna/laravel-html-fragment-cache without Composer
On this page you can find all versions of the php package iperamuna/laravel-html-fragment-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download iperamuna/laravel-html-fragment-cache
More information about iperamuna/laravel-html-fragment-cache
Files in iperamuna/laravel-html-fragment-cache
Package laravel-html-fragment-cache
Short Description A lightweight, generic HTML fragment caching package for Laravel. Cache any rendered HTML by identifier with support for all Laravel cache drivers, Blade directives, and simple invalidation.
License MIT
Homepage https://github.com/iperamuna/laravel-html-fragment-cache
Informations about the package laravel-html-fragment-cache
Laravel HTML Fragment Cache
A lightweight, generic HTML fragment caching package for Laravel. Cache any rendered HTML by identifier (customer/org/user/etc.) with support for all Laravel cache drivers, Blade directives, and simple invalidation.
Features
- 🚀 Laravel 10/11/12 compatible
- 💾 Universal cache support - Works with Redis, Memcached, Database, File, Array, DynamoDB, and Octane
- 🎯 Identifier-based caching - Cache by customer, organization, user, or any identifier
- 🏷️ Blade directive - Simple
@fragmentCachedirective for quick caching - ⚡ Performance optimized - Skip database queries and Blade rendering on cache hits
- 🔧 Configurable cache store - Use any cache store from your Laravel configuration
- 🎨 Clean API - Simple facade and trait-based usage
- 🛠️ Artisan commands - Interactive commands for cache management
Installation
You can install the package via Composer:
The package will automatically register its service provider and facade.
Publish Configuration (Optional)
This will publish config/fragment-cache.php where you can customize the default settings.
Configuration
The package uses Laravel's cache system and supports all cache drivers. You can configure which cache store to use and enable/disable caching globally:
Available Configuration Options
Enabling/Disabling Caching
You can globally enable or disable fragment caching using the enabled configuration option:
When caching is disabled:
- All
rememberHtml()calls will execute the builder function directly without caching forget()calls will do nothing- Blade directives will render content directly without caching
- This is useful for development, debugging, or when you want to temporarily disable caching
Usage
Basic Usage with Facade
Blade Directive
The package provides a convenient Blade directive for quick caching:
You can also pass an array as identifier to include additional context:
Using the Trait
For more complex scenarios, use the UsesHtmlFragmentCache trait:
Livewire Integration
Perfect for caching expensive Livewire component rendering:
Using the Trait (Recommended)
Using the Facade
Cache Invalidation
Forget Specific Fragments
Artisan Commands
The package provides interactive Artisan commands for cache management:
The fragment-cache:forget command provides three modes:
- Forget by Identifier: Remove specific cached fragments
- Forget by Pattern: Clear fragments matching a pattern (flushes entire cache store)
- Flush All: Clear all fragments from the configured cache store
Advanced Usage
Custom Identifier Resolution
You can customize how identifiers are resolved by modifying the configuration or creating a custom resolver:
Multiple Cache Stores
You can use different cache stores for different environments:
Performance Benefits
- Skip Database Queries: Cache the final rendered HTML, not just database results
- Skip Blade Rendering: Avoid expensive view compilation on cache hits
- Universal Compatibility: Works with any Laravel cache driver
- Memory Efficient: Uses Laravel's built-in cache system
Testing
The test suite uses Orchestra Testbench with the array cache driver for portability.
Requirements
- PHP 8.2+
- Laravel 10.0+ | 11.0+ | 12.0+
- Laravel Prompts (for interactive commands)
Cache Driver Support
| Driver | Support | Notes |
|---|---|---|
| Array | ✅ Full | Perfect for testing |
| File | ✅ Full | Good for single-server setups |
| Database | ✅ Full | Persistent across servers |
| Redis | ✅ Full | High performance, recommended for production |
| Memcached | ✅ Full | High performance, in-memory |
| DynamoDB | ✅ Full | AWS managed cache |
| Octane | ✅ Full | Ultra-high performance |
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Indunil Peramuna
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
Made with ❤️ for the Laravel community
All versions of laravel-html-fragment-cache with dependencies
illuminate/support Version ^10.0 || ^11.0 || ^12.0
laravel/prompts Version ^0.3.7