PHP code example of galancev / smart-cache

1. Go to this page and download the library: Download galancev/smart-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/ */

    

galancev / smart-cache example snippets


use Components\Cache\SmartCache;

$cache = (new SmartCache())
    ->setGroup('test')
    ->setKey('supertest1')
    ->setExpire(5)
    ->get();

if ($cache->hasResult()) {
    $need = $cache->getResult();
} else {
    $need = rand(0, 666);

    $cache->set($need);
}

Dev::pre($need);

$cache = SmartCache::factory([
    'group' => 'test',
    'key' => 'supertest1',
    'expire' => 5,
    'scatter' => 0,
])->get();

$cache = SmartCache::init('test', 'supertest1', 5, 0);

$data = (new SmartCache())
    ->setGroup('test')
    ->setKey('test')
    ->setExpire(5)
    ->remember(function () {
        $res = App::$DB->Query('SELECT * FROM b_user LIMIT 1');

        if(!$res)
            return false;

        return $res->FetchAll();
    });