salehhashemi / laravel-configurable-cache
Configurable Laravel cache manager
Installs: 6 651
Dependents: 1
Suggesters: 0
Security: 0
Stars: 20
Watchers: 4
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- laravel/framework: ^9.0|^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.8
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.0|^10.0|^11.0
README
Laravel Configurable Cache
Features
- Provides configurable cache settings with dedicated ttl and prefix for each
- Supports all main cache operations provided by Laravel, such as put, get, increment, and delete
Requirements
PHP: ^8.1
Laravel framework: ^9
Installation
You can install the package via composer:
composer require salehhashemi/laravel-configurable-cache
Next, from the command line type:
php artisan vendor:publish --provider="Salehhashemi\ConfigurableCache\ConfigurableCacheServiceProvider"
Finally, adjust the settings in the published configuration file located in config/configurable-cache.php
as per your
requirements.
Usage
To use the package, you can use the ConfigurableCache
class methods. Here's an example:
use Salehhashemi\ConfigurableCache\ConfigurableCache; // Storing an item in the cache with `_tiny_` prefix for 15 minutes ConfigurableCache::put('testKey', 'Hello World!', 'tiny'); // Retrieving an item from the cache with `_short_` prefix that is stored for an hour $value = ConfigurableCache::get('testKey', 'short'); // Delete a cache item with `_otp_` prefix ConfigurableCache::delete('testKey', 'otp'); // if `testKey` doesn't exist in the 'default' cache, the Closure will be executed and its result will be stored in the cache under `testKey` with `_default_` prefix $value = ConfigurableCache::remember('testKey', function () { return 'Hello World!'; });
Default configuration
You can change these configurations in your configurable-cache.php config file:
'configs' => [
'default' => [
'prefix' => '_default_',
'duration' => '+1 Year',
],
'tiny' => [
'prefix' => '_tiny_',
'duration' => '+15 minutes',
],
'short' => [
'prefix' => '_short_',
'duration' => '+1 hour',
],
'otp' => [
'prefix' => '_otp_',
'duration' => '+3 minutes',
],
]
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.