PHP code example of vemcogroup / model-cache

1. Go to this page and download the library: Download vemcogroup/model-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vemcogroup / model-cache example snippets


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


self::clearLocalCache();