Skip to content

vemcogroup/model-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Model local cache

Latest Version on Packagist Total Downloads

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();

About

Static cache instead of re-hitting cache server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages