Download the PHP package vormkracht10/laravel-permanent-cache without Composer
On this page you can find all versions of the php package vormkracht10/laravel-permanent-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vormkracht10/laravel-permanent-cache
More information about vormkracht10/laravel-permanent-cache
Files in vormkracht10/laravel-permanent-cache
Package laravel-permanent-cache
Short Description Using Laravel Permanent Cache you can cache intensive operations permanently and update them in the background, so your users don't have to wait!
License MIT
Homepage https://github.com/vormkracht10/laravel-permanent-cache
Informations about the package laravel-permanent-cache
Laravel Permanent Cache
This package aims to provide functionality of using a permanent cache for tasks using heavy Eloquent models, database queries or other long running tasks in your Laravel app. The permanent cache updates itself in the background using a scheduled task or by listening to an event so no users are harmed waiting on a given request.
Its use case is primarily to be used for heavy tasks that should return complex data or HTML for the front-end that does not need to be realtime but still regularly updated. Think about external API calls that take a few seconds to process or other 1+ second tasks.
Installation
You can install the package via composer:
Optionally, publish config files to change the default config:
The default config options:
Usage
All caches you create must be registered to the PermanentCache::caches
facade.
We recommend putting this in the boot
method of your AppServiceProvider
.
You can register caches in multiple ways:
Definition of a Permanent Cache
A Permanent Cache could be a task that runs longer than you'd want your users to wait for. That's why you need to run it in the background, updating periodically using the scheduler or when events happen and/or using help of Laravel's queue system.
You can define the cache store and key using a $store
property on the class, following
the definition: cache-driver:key
, for example: redis:a-unique-cache-key
:
Caches can listen for events
If you only want to listen for a single event you can type hint the event in the run
method:
Listening for multiple events
Permanent Caches can be updated by listening to multiple events using an array on the $events
property:
Caches can be updated periodically using the scheduler
Permanent Caches can be updated using the scheduler (while also listening for events) by adding a schedule
method or a $expression
property with a cron string.
Note that if you decide to listen to events and schedule your cache, you shouldn't try to
accept an $event
parameter in the run
method, because when the schedule runs, this won't be given to you.
Caches can be updated by dispatching on the queue
Permanent Caches can be updated using a dispatch to the queue by implementing Laravel's ShouldQueue
interface and (optionally) specifying a queue:
Feature: Cached Blade Components
One super handy feature are "Cached Components", these are Blade Components that could contain a longer running task on which you don't want your users to wait for completing. So you execute the Blade component when needed in the background, using the scheduler, or queue, while optionally listening for events to happen that will cause the permanent cache to update.
When loading your Blade component, it will always use cache instead of executing a long during task:
Manually updating permanent caches
Manually updating a permanent cache is very simple. Just use the static update
method.
This will automatically run or queue the execution of the task:
Or you can update all caches at once:
Events when updating Permanent Caches
These events get dispatched when a Permanent Cache gets updated:
Console commands
This package contains Artisan commands to optimize DX when implementing Permanent Cache:
Read more on Jobs & Queues
Credits
- Mark van Eijk
- David den Haan
- All Contributors
License
The MIT License (MIT). Please see the License File for more information.
All versions of laravel-permanent-cache with dependencies
illuminate/contracts Version ^10.0|^11.0
laravel/helpers Version ^1.7
lorisleiva/cron-translator Version ^0.4.5
spatie/emoji Version ^4.1
spatie/laravel-package-tools Version ^1.14.0