vemcogroup / model-cache
Static cache instead of re-hitting cache server
Installs: 25 530
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
This package is auto-updated.
Last update: 2024-10-29 05:16:53 UTC
README
Description
This package allows to have static local cache on your models.
It can both be used with a cache server or without.
Installation
You can install the package via composer:
composer require vemcogroup/model-cache
Usage
It's easy to use the trait in your own class just Use the trait as below
use Vemcogroup\ModelCache\Traits\HaslocalCache; class DataRepository { use HasLocalCache; public function getData($userId) { $localCacheKey = 'getData.'.$userId; /* * If localCache exists with key return cache */ if ($cache = self::getLocalCache($localCacheKey)) { return $cache; } // Run DB query or Cache code $result = [1, 2, 3, 4, 5, 6]; /* * Remember to save your DB query or Cache result */ self::setLocalCache($localCacheKey, $result); return $result; } }
If you need to clear the Cache you can use the clear method
self::clearLocalCache();