PHPackages                             dv0vd/laravel-simple-cache - 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. dv0vd/laravel-simple-cache

ActiveLibrary[Caching](/categories/caching)

dv0vd/laravel-simple-cache
==========================

Simple trait for cache handling with tags support in Laravel

1.0.0(7mo ago)01MITPHPPHP &gt;=8.1

Since Nov 27Pushed 4mo agoCompare

[ Source](https://github.com/dv0vd/laravel-simple-cache)[ Packagist](https://packagist.org/packages/dv0vd/laravel-simple-cache)[ Docs](https://github.com/dv0vd/laravel-simple-cache)[ RSS](/packages/dv0vd-laravel-simple-cache/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Laravel Simple Cache Trait
==========================

[](#laravel-simple-cache-trait)

A lightweight Laravel trait that simplifies working with cache keys and tagged cache storage. It automatically generates stable hashed cache keys, handles nested arrays, sorts key data, and supports cache tags across all Laravel versions starting from **8.x**.

Features
--------

[](#features)

- Automatic cache key generation using SHA-256
- Deterministic sorting of array keys before hashing
- Tagged cache support (if the store supports it)
- Graceful fallback when caching fails
- Easy cache flushing for specific tag groups
- Works on Laravel **8+**

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

[](#installation)

```
composer require dv0vd/laravel-simple-cache
```

Usage
-----

[](#usage)

```
use Dv0vD\LaravelSimpleCache\CacheTrait;

class ProductRepository
{
    use CacheTrait;

    public function get(int $id)
    {
        return $this->rememberCache(
            callback: fn () => Product::find($id),
            keys: ['id' => $id],
        );
    }
}
```

Tag Constants (optional):

```
class ProductRepository
{
    use CacheTrait;

    private const CACHE_MAIN_TAG = 'products';
    private const CACHE_TAGS = ['repository', 'models'];

    public function get(int $id)
    {
        return $this->rememberCache(
            callback: fn () => Product::find($id),
            keys: ['id' => $id],
        );
    }
}
```

Clearing cache:

```
$this->clearCache();
```

```
$this->clearCache(['products']);
```

Available Methods
-----------------

[](#available-methods)

### rememberCache(callable $callback, array $keys = \[\], array $tags = \[\], ?int $ttl = null): mixed

[](#remembercachecallable-callback-array-keys---array-tags---int-ttl--null-mixed)

Stores or retrieves a value from cache:

- Automatically generates a cache key based on the calling class, method, and the `$keys` array (sorted &amp; hashed).
- Uses tags if the cache driver supports them.
- Logs and silently falls back to the callback if caching fails.
- `$ttl` (in seconds) is optional. Defaults to `cache.ttl` from your config.

### clearCache(array $tags = \[\]): void

[](#clearcachearray-tags---void)

Flushes all cache entries for the provided tags or default tags.

- By default, tags are taken from the constants `CACHE_MAIN_TAG` and `CACHE_TAGS`.
- If you pass tags as a parameter, they will override the default constants.
- Only cache entries with tags are cleared.
- If no tags are found, the method does nothing to avoid accidental data loss.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance70

Regular maintenance activity

Popularity1

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

219d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/100205424?v=4)[Viacheslav Davydov](/maintainers/dv0vd)[@dv0vd](https://github.com/dv0vd)

---

Tags

laraveltraitrediscachetagged cache

### Embed Badge

![Health badge](/badges/dv0vd-laravel-simple-cache/health.svg)

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k91.0k1](/packages/mike-bronner-laravel-model-caching)[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M6](/packages/propaganistas-laravel-disposable-email)[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

973172.3k2](/packages/awssat-laravel-visits)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21111.6k](/packages/iazaran-smart-cache)

PHPackages © 2026

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