PHPackages                             nnjeim/persist - 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. nnjeim/persist

ActiveLaravel-package[Caching](/categories/caching)

nnjeim/persist
==============

Laravel cache helper methods

1.0.1(4y ago)150MITPHPPHP &gt;=7.4

Since Sep 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/nnjeim/persist)[ Packagist](https://packagist.org/packages/nnjeim/persist)[ Docs](https://github.com/nnjeim/persist)[ RSS](/packages/nnjeim-persist/feed)WikiDiscussions master Synced 1mo ago

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

[![](https://camo.githubusercontent.com/00febf8cd7a1fb21c09c3392694c065f864890c18fd816bae46060d9d64fb59f/68747470733a2f2f65752e75692d617661746172732e636f6d2f6170692f3f6e616d653d4e616a6d2b4e6a65696d3f73697a653d313030)](https://camo.githubusercontent.com/00febf8cd7a1fb21c09c3392694c065f864890c18fd816bae46060d9d64fb59f/68747470733a2f2f65752e75692d617661746172732e636f6d2f6170692f3f6e616d653d4e616a6d2b4e6a65696d3f73697a653d313030)

nnjeim Persist Helper
---------------------

[](#nnjeim-persist-helper)

A Laravel cache helper methods.

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

[](#installation)

You can install the package via composer:

```
composer require nnjeim/persist

```

Usage
-----

[](#usage)

##### Persist Facade

[](#persist-facade)

```
use Nnjeim\Fetch\Fetch;
use Nnjeim\Respond\Respond;
use Nnjeim\Persist\Persist;

class Country {

	public function index() {

		if (Persist::setCacheTag('countries')->setCacheKey('index')->hasCacheKey()) {

			return Respond::toJson()
				->setMessage('countries')
				->setData(
					Persist::setCacheTag('countries')
						->setCacheKey('index')
						->getCacheKey()
				)
				->withSuccess();
		}

		['response' => $response, 'status' => $status] = Fetch::setBaseUri('https://someapi.com')->get('countries');

			if ($status === 200 && $response->success) {

				$data = Persist::setCacheTag('countries')
					->setCacheKey('index')
					->rememberCacheForever($response->data);H

				return Respond::toJson()
					->setMessage('countries')
					->setData($data)
					->withSuccess();
			}

			return Respond::withErrors();
	}
}

```

##### PersistHelper Instantiation

[](#persisthelper-instantiation)

```
use Nnjeim\Persist\PersistHelper;
use Nnjeim\Fetch\FetchHelper;
use Nnjeim\Respond\RespondHelper;

class Country {

	private PersistHelper $persist;
	private FetchHelper $fetch;
	private RespondHelper $respond;

	public function __construct(
		PersistHelper $persist,
		FetchHelper $fetch,
		RespondHelper $respond
		) {

		$this->persist = $persist;
		$this->fetch = $fetch;
		$this->respond = $respond;

		$this->persist->setCacheTag = 'countries';
		$this->fetch->setBaseUri = 'https://someapi.com';
	}

	public function index() {

		$this->persist->setCacheKey = 'index';

		if ($this->persist->hasCacheKey()) {

			return $this->respond
				->toJson()
				->setData($this->persist->getCacheKey())
				->withSuccess();
		}

		['response' => $response, 'status' => $status] = $this->fetch->get('countries');

		if ($status === 200 && $response->success) {

			$data = $this->persist->rememberCacheForever($response->data);

			return $this->respond
                ->toJson()
                ->setData($data)
                ->withSuccess();
		}

		return $this->respond->withErrors();
	}
}

```

Methods
-------

[](#methods)

##### Set the cache tag

[](#set-the-cache-tag)

```
Sets the cache tag string | array

@return $this       setCacheTag(string | array $cacheTag, $suffix = null)

```

##### Set the cache key

[](#set-the-cache-key)

```
Sets the cache key string

@return $this       setCacheKey(string $cacheKey)

```

##### Form a composite cache key

[](#form-a-composite-cache-key)

```
sets the cache key with the result of the concatenatenation of multiple strings with an '_' seprator.

@return $this       formCacheKey(array $strings) or formCacheKey($string1, $string2, ...)

```

##### Cache Key exist

[](#cache-key-exist)

```
Asserts if a cache key exists

@return bool       hasCacheKey(string $cacheKey)

```

##### Get a cache key

[](#get-a-cache-key)

```
Returns the peristed cache key.

@return mixed       getCacheKey(string $cacheKey)

```

##### Remember cache

[](#remember-cache)

```
returns the cached value for a given number of seconds

@return mixed       rememberCache($value, $ttl)

```

##### Remember cache forever

[](#remember-cache-forever)

```
returns the cached value

@return mixed       rememberCacheForever($value)

```

##### Forget a cache key

[](#forget-a-cache-key)

```
Clears the cache of the given cache key.

@return void       forgetCacheKey(string $cacheKey)

```

##### Flush the cache by Tag

[](#flush-the-cache-by-tag)

```
Clears all the cache keys related to a given cache tag

@return void       flushCacheTag()

```

##### Increment a cache key

[](#increment-a-cache-key)

```
Increments a cache key by a given value. default = 1.

@return void       incrementCacheKey($amount = 1)

```

##### Decrement a cache key

[](#decrement-a-cache-key)

```
Decrements a cache key by a given value. default = 1.

@return void       decrementCacheKey($amount = 1)

```

Changelog
---------

[](#changelog)

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

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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 ~5 days

Total

2

Last Release

1702d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c7c0bbf68a5085c71eb582298250ac2ffe5b4a971bd4fda304a1a6e3ec3bd02?d=identicon)[nnjeim](/maintainers/nnjeim)

---

Top Contributors

[![nnjeim](https://avatars.githubusercontent.com/u/78922079?v=4)](https://github.com/nnjeim "nnjeim (2 commits)")

---

Tags

cachehelperslaravellaravel-packageredislaravelhelperslumenrediscache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nnjeim-persist/health.svg)

```
[![Health](https://phpackages.com/badges/nnjeim-persist/health.svg)](https://phpackages.com/packages/nnjeim-persist)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[vink/nova-cache-card

Manage your application's cache from a handy Laravel Nova dashboard card.

26317.3k1](/packages/vink-nova-cache-card)[ginnerpeace/laravel-redis-lock

Simple redis distributed locks for Laravel.

15114.4k](/packages/ginnerpeace-laravel-redis-lock)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)[michele-angioni/support

Support is a Laravel package which promotes the use of best practices and design patterns.

181.4k1](/packages/michele-angioni-support)

PHPackages © 2026

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