PHPackages                             henzeb/laravel-cache-index - 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. henzeb/laravel-cache-index

ActiveLibrary[Caching](/categories/caching)

henzeb/laravel-cache-index
==========================

Flexible replacement for tags

v1.5.1(1y ago)1213.9k↓29.2%3[1 PRs](https://github.com/henzeb/laravel-cache-index/pulls)AGPL-3.0-onlyPHPPHP ^8.1CI passing

Since Jan 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/henzeb/laravel-cache-index)[ Packagist](https://packagist.org/packages/henzeb/laravel-cache-index)[ Docs](https://github.com/henzeb/laravel-console-facade)[ RSS](/packages/henzeb-laravel-cache-index/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (8)Versions (9)Used By (0)

Cache Index for Laravel
=======================

[](#cache-index-for-laravel)

[![Build Status](https://github.com/henzeb/laravel-cache-index/workflows/tests/badge.svg)](https://github.com/henzeb/laravel-cache-index/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/dd0cfc2b8a9b4f7e9c6e3c67dd20607d68627c9e085ee73111bddf96ab9154af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656e7a65622f6c61726176656c2d63616368652d696e6465782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/laravel-cache-index)[![Total Downloads](https://camo.githubusercontent.com/ccb953c9ece8e345f947bf7d2462af1d866a5f0a1291206abbdcada0a183481b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656e7a65622f6c61726176656c2d63616368652d696e6465782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/henzeb/laravel-cache-index)[![Test Coverage](https://camo.githubusercontent.com/1f97d6f9c8ee9d21c20689f6e3dc74cf5f59dc6881d9078384959baa17cfe123/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f36346465313734616431653063323638303336312f746573745f636f766572616765)](https://codeclimate.com/github/henzeb/laravel-cache-index/test_coverage)[![License](https://camo.githubusercontent.com/a8050652d2208bae09131bbe177179163a7a739b384abad1eec4e1da73967f47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68656e7a65622f6c61726176656c2d63616368652d696e646578)](https://packagist.org/packages/henzeb/laravel-cache-index)

When you have a situation where you need to be able to track keys, you can use [tags](https://laravel.com/docs/master/cache#cache-tags). Unfortunately tags aren't supported by all drivers, and retrieving keys is only doable the hacky way with redis.

Cache Index for Laravel provides a driver-independent way for managing such indexes.

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

[](#installation)

Just install with the following command.

```
composer require henzeb/laravel-cache-index
```

Usage
-----

[](#usage)

Under the hood, `index` returned an extended `Illuminate\Cache\Repository`object, which manages your index.

See [Laravel doc's](https://laravel.com/docs/master/cache)for the possible methods.

keys are prefixed with the index name, so that you can't accidentally overwrite any values belonging to that index.

Note: tags are currently not supported when using `index`.

```
Cache::index('myIndex')->add('test', 'my value');
Cache::index('myIndex')->put('put', 'my value');

Cache::driver('file')->index('myIndex')->remember('filed', 'my value in file');

Cache::index('myIndex')->get('put'); // returns 'my value'
Cache::get('put'); // returns null

Cache::index('myIndex')->flush(); // only flushes keys in index
```

### index name

[](#index-name)

The index name can, next to a regular string, also be applied as an array. This is handy when you have an index based on variables.

```
Cache::index(['myIndex', 'Read', 'Write']); // uses index name `myIndex.Read.Write`
Cache::index(['myIndex', ActionEnum::Read]); // uses index name `myIndex.Read`
Cache::index(['myIndex', new StdClass()]); // uses index name `myIndex.StdClass`
Cache::index(['myIndex', new StringableClass('stringed')]); // uses index name `myIndex.stringed`
```

### Keys

[](#keys)

Retrieving a list of keys is very easy.

```
Cache::index('myIndex')->keys(); // returns ['test', 'put']
Cache::driver('file')->index('myIndex')->keys(); // returns ['filed']
```

### Count

[](#count)

With this method, you can know how many keys are inside your index.

```
Cache::index('myIndex'); // using default driver
Cache::driver('file')->index('myIndex'); // using file driver
```

### Copy &amp; Move

[](#copy--move)

#### Copy

[](#copy)

Makes a copy of a cached item, and adds the key in the new index.

It returns true if it's successful, false otherwise.

```
Cache::index('myIndex')->copy('myKey', 'targetIndex');
Cache::index('myIndex')->copy('myKey', 'targetIndex', 10);
```

#### Move

[](#move)

Does the same as `Copy`, except that it removes its own copy.

It returns true if it's successful, false otherwise.

```
Cache::index('myIndex')->move('myKey', 'targetIndex');
Cache::index('myIndex')->move('myKey', 'targetIndex', 10);
```

Note: Be aware that either copy and move do nothing with the TTL. It creates a new copy of the cached item with a new TTL if given.

### pop

[](#pop)

Just like with arrays, takes and removes the last indexed key and returns the value associated with that index.

### shift

[](#shift)

Just like with arrays, takes and removes the first indexed key and returns the value associated with that index.

### random

[](#random)

returns a random value.

### randomKey

[](#randomkey)

returns a random key.

### pullRandom

[](#pullrandom)

Returns a random value and pulls it from the cache.

### syncTtl

[](#syncttl)

Allows you to synchronize the ttl between indexed keys.

```
Cache::index('myIndex')->syncTtl(10);
Cache::index('myIndex')->syncTtl(now()->addSeconds(10));
```

Testing this package
--------------------

[](#testing-this-package)

```
composer test
```

Changelog
---------

[](#changelog)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Henze Berkheij](https://github.com/henzeb)

License
-------

[](#license)

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

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance49

Moderate activity, may be stable

Popularity35

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% 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 ~119 days

Recently: every ~201 days

Total

8

Last Release

370d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.4.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15928532?v=4)[henzeb](/maintainers/henzeb)[@henzeb](https://github.com/henzeb)

---

Top Contributors

[![henzeb](https://avatars.githubusercontent.com/u/15928532?v=4)](https://github.com/henzeb "henzeb (9 commits)")[![fridzema](https://avatars.githubusercontent.com/u/8180660?v=4)](https://github.com/fridzema "fridzema (1 commits)")[![SebKay](https://avatars.githubusercontent.com/u/1873695?v=4)](https://github.com/SebKay "SebKay (1 commits)")

---

Tags

laravelcacheindexhenzeb

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/henzeb-laravel-cache-index/health.svg)

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[dragon-code/laravel-cache

An improved interface for working with cache

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

A handful of Cloudflare cache helpers for Laravel

1317.7k](/packages/nexxai-laravel-cfcache)[omaralalwi/lexi-translate

Laravel translation package with morph relationships and caching.

754.3k2](/packages/omaralalwi-lexi-translate)[karriere/state

Laravel package for storing current application state in cache/session

1718.5k](/packages/karriere-state)

PHPackages © 2026

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