New

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

nnjeim/persist

Laravel cache helper methods
60 1

Larablocks Analysis

nnjeim/persist works with any PHP project: the latest release (1.0.1, Sep 18, 2021) doesn't depend on Laravel.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • No release in the last 12 months (last: Sep 18, 2021)
  • 0 downloads a month (needs 10,000)
  • 1 GitHub star (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Sep 18, 2021.
  • No releases in the last 12 months.
  • First released: Sep 13, 2021.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 3, 2026.

Install
composer require nnjeim/persist
Latest Version:1.0.1
PHP:>=7.4
License:MIT
Last Updated:Sep 18, 2021
Links: GitHub  ·  Packagist
Maintainer: nnjeim

nnjeim Persist Helper

A Laravel cache helper methods.

Installation

You can install the package via composer:

composer require nnjeim/persist

Usage

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
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

Set the cache tag
Sets the cache tag string | array

@return $this       setCacheTag(string | array $cacheTag, $suffix = null)
Set the cache key
Sets the cache key string 

@return $this       setCacheKey(string $cacheKey)
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
Asserts if a cache key exists

@return bool       hasCacheKey(string $cacheKey)
Get a cache key
Returns the peristed cache key.

@return mixed       getCacheKey(string $cacheKey)
Remember cache
returns the cached value for a given number of seconds

@return mixed       rememberCache($value, $ttl)
Remember cache forever
returns the cached value

@return mixed       rememberCacheForever($value)
Forget a cache key
Clears the cache of the given cache key.   

@return void       forgetCacheKey(string $cacheKey)
Flush the cache by Tag
Clears all the cache keys related to a given cache tag

@return void       flushCacheTag()
Increment a cache key
Increments a cache key by a given value. default = 1.

@return void       incrementCacheKey($amount = 1)
Decrement a cache key
Decrements a cache key by a given value. default = 1.

@return void       decrementCacheKey($amount = 1)

Changelog

Please see CHANGELOG for more information what has changed recently.

Alternatives to nnjeim/persist

awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

192,002 972
byerikas/cache-tags

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

36,124 14
padosoft/laravel-super-cache

A Laravel package for advanced caching with tags and namespaces in Redis.

11,776 3
dreamfactory/df-cache

Cache service for DreamFactory Platform 2.0

44,966 1
mostafaznv/nova-laracache

LaraCache Tool for Laravel Nova

6,211 11

Version History

Version Released PHP License
1.0.1 >=7.4 MIT
1 >=7.4 MIT