PHPackages                             develupers/laravel-cache-compress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. develupers/laravel-cache-compress

ActiveLibrary[Caching](/categories/caching)

develupers/laravel-cache-compress
=================================

Add compression support to your Laravel cache. (MongoDB, Redis, Memcached and MySQL supported)

v0.6.0(11mo ago)195MITPHPPHP ^8.2CI passing

Since May 16Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/develupers/laravel-cache-compress)[ Packagist](https://packagist.org/packages/develupers/laravel-cache-compress)[ Docs](https://github.com/develupers/laravel-cache-compress)[ GitHub Sponsors](https://github.com/Develupers)[ RSS](/packages/develupers-laravel-cache-compress/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (13)Versions (8)Used By (0)

Laravel Cache Compress
======================

[](#laravel-cache-compress)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cd6e55456fe20af236bc286ba21a89442fcc6fbf33040807cc0ea02be1c3987d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646576656c75706572732f6c61726176656c2d63616368652d636f6d70726573732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/develupers/laravel-cache-compress)[![GitHub Tests Action Status](https://camo.githubusercontent.com/7c7497158b2f4952389b543be8a374ae518ee61cdd427037fb538fa492ecf590/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f646576656c75706572732f6c61726176656c2d63616368652d636f6d70726573732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/develupers/laravel-cache-compress/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d4c74cd38bbfe68220f3421e31384a624205295d9aec70de2cb37c5ffa2c78d8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f646576656c75706572732f6c61726176656c2d63616368652d636f6d70726573732f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/develupers/laravel-cache-compress/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/f0506797d373744738a7d7cbeab1a4bc40600011982b907957336b5feae01984/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646576656c75706572732f6c61726176656c2d63616368652d636f6d70726573732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/develupers/laravel-cache-compress)

A Laravel package that adds compression to your Laravel cache, reducing storage requirements for large cache values.

Features
--------

[](#features)

- Automatically compresses cache values before storage
- Automatically decompresses values when retrieved
- Compatible with all Laravel cache drivers
- Special handling for MongoDB to ensure UTF-8 compatibility
- Control compression via environment variables or per-call settings
- Compatible with Laravel's Cache Tags

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10|11+
- PHP zlib extension (for compression)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require develupers/laravel-cache-compress
```

You can publish the config file with:

```
php artisan vendor:publish --tag="cache-compress-config"
```

This is the contents of the published config file:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Enable Cache Compression
    |--------------------------------------------------------------------------
    |
    | This option controls whether cache compression is enabled.
    | You can disable it by setting this to false.
    |
    */
    'enabled' => env('CACHE_COMPRESS_ENABLED', true),

    /*
    |--------------------------------------------------------------------------
    | Compression Level
    |--------------------------------------------------------------------------
    |
    | This option controls the compression level used by gzdeflate.
    | The value must be between 0 and 9, where:
    | 0 = no compression
    | 1 = minimal compression (fastest)
    | 9 = maximum compression (slowest)
    |
    */
    'compression_level' => env('CACHE_COMPRESS_LEVEL', 6),
];
```

Usage
-----

[](#usage)

### Using with Laravel's Cache Facade

[](#using-with-laravels-cache-facade)

The package adds a `compress()`, `decompress()`, `withoutCompress()` and `withoutDecompress()` method to Laravel's standard `Cache` facade:

```
use Illuminate\Support\Facades\Cache;

// Store with compression
Cache::compress()->put('key', $largeObject, 60); // 60 minutes

// Retrieve compressed data
$value = Cache::compress()->get('key');
// or
$value = Cache::decompress()->get('key');

// With a specific store
Cache::store('redis')->compress()->put('key', $value, 60);
$value = Cache::store('redis')->decompress()->get('key');
```

**Note:** `decompress()` is just a shortcut for `compress()` and `withoutDecompress()` is just a shortcut for `withoutCompress()`.

### Using the Dedicated CacheCompress Facade

[](#using-the-dedicated-cachecompress-facade)

Alternatively, you can use the dedicated `CacheCompress` facade:

```
use Develupers\CacheCompress\Facades\CacheCompress;

// Store a value in the cache (will be compressed)
CacheCompress::put('key', $largeObject, 60); // 60 minutes

// Retrieve and automatically decompress the value
$value = CacheCompress::get('key');
```

### Specifying a Store

[](#specifying-a-store)

You can specify which cache store to use:

```
// Use the Redis store
$value = CacheCompress::store('redis')->get('key');

// Store with the file driver
CacheCompress::store('file')->put('key', $value, 60);
```

### Completely Replace Laravel's Cache Facade (Optional)

[](#completely-replace-laravels-cache-facade-optional)

If you want to use compression for all cache operations by default, you can replace Laravel's Cache facade with our CacheCompress facade by adding the following to your `config/app.php`:

```
'aliases' => Facade::defaultAliases()->merge([
    //...
    'Cache' => Develupers\CacheCompress\Facades\CacheCompress::class,
    //...
]),
```

With this change, all `Cache::` calls in your application will automatically use compression without any additional code changes.

```
Cache::put('key', $value, 60); // This will be compressed
$value = Cache::get('key'); // This will be decompressed
```

Note: Automatic compress only applies when `CACHE_COMPRESS_ENABLED` is set to `true`.

To disable compression for a specific operation at runtime, set `compress(false)`. For example:

```
Cache::compress(false)->put('key', $value, 60);
Cache::compress(false)->get('key');
// or
Cache::withoutCompress()->put('key', $value, 60);
Cache::withoutDecompress()->get('key');
```

### All Standard Cache Methods Supported

[](#all-standard-cache-methods-supported)

All standard Laravel cache methods are supported:

```
// Remember a pattern
$value = CacheCompress::remember('key', 60, function () {
    return expensive_operation();
});

// Forever
CacheCompress::forever('key', $value);

// Multiple items
$values = CacheCompress::many(['key1', 'key2']);

// Check if exists
if (CacheCompress::has('key')) {
    // ...
}

// Delete
CacheCompress::forget('key');
```

Environment Variables
---------------------

[](#environment-variables)

You can control compression through environment variables:

```
CACHE_COMPRESS_ENABLED=true
CACHE_COMPRESS_LEVEL=6

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance50

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

357d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f1328878cac7a1d4cab5ba224bef33b33692bf748d8fe6ed9d76605a373a6c6?d=identicon)[develupers](/maintainers/develupers)

---

Top Contributors

[![develupers](https://avatars.githubusercontent.com/u/171888109?v=4)](https://github.com/develupers "develupers (79 commits)")

---

Tags

laravelcompressioncachedevelupers

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/develupers-laravel-cache-compress/health.svg)

```
[![Health](https://phpackages.com/badges/develupers-laravel-cache-compress/health.svg)](https://phpackages.com/packages/develupers-laravel-cache-compress)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[silber/page-cache

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

1.3k441.9k6](/packages/silber-page-cache)[ryangjchandler/blade-cache-directive

Cache chunks of your Blade markup with ease.

202200.8k2](/packages/ryangjchandler-blade-cache-directive)[yediyuz/laravel-cloudflare-cache

laravel-cloudflare-cache

28239.2k](/packages/yediyuz-laravel-cloudflare-cache)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k10](/packages/dragon-code-laravel-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
