New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

salehhashemi/laravel-configurable-cache

Configurable Laravel cache manager
16,727 21
Install
composer require salehhashemi/laravel-configurable-cache
Latest Version:v1.5.0
PHP:^8.2
Laravel:12 · 13
Older releases:9 · 10 · 11
License:MIT
Last Updated:Jun 15, 2026
Links: GitHub  ·  Packagist
Maintainer: salehhashemi

Laravel Configurable Cache

Latest Version on Packagist Total Downloads GitHub Actions GitHub Actions codecov PHPStan PHP Version Require

Header Image

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.2
  • Laravel framework: ^12
Version L12 L13
2.0 :white_check_mark: :white_check_mark:

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.

Related Packages

bunkuris/has-cache

HasCache trait for Laravel models with cache key managers

3,573 0
silber/page-cache

Caches responses as static files on disk for lightning fast page loads.

519,531 1,258
laracasts/matryoshka

Russian Doll Caching for Laravel.

60,984 237
geekcache/geekcache

A wrapper for Memcached with tags, soft invalidation, memoization, and regenerat...

38,858 6
mitydigital/statamic-scheduled-cache-invalidator

A command to help invalidate the cache when scheduled Statamic entries are due t...

31,287 3

Version History

Version Released PHP Laravel License
v1.5.0 ^8.2 ^12.0|^13.0 MIT
v1.4.0 ^8.1 ^9.0|^10.0|^11.0 MIT
v1.3.0 ^8.1 ^9.0|^10.0 MIT
v1.2.0 ^8.1 ^9.0|^10.0 MIT
v1.1.0 ^8.1 ^9.0|^10.0 MIT