PHP code example of tarcisiojr / php-cache

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

    

tarcisiojr / php-cache example snippets




class ClasseQualquer  {

    public function gerarNroAleatorio() {
        return Cache::create(function () {
            return rand(1, 100);
        })
            ->once()        // Cacheia o valor uma única vez.
            ->statefull()   // Cache existente apenas em nivel de request.
            ->scope(false)  // Cache do método entre instâncias.
            ->ttl(10)       // Tempo do cache sera de 10 segundos.
            ->get();        // Executa a obtenção do valor
    }
}

\Cache\API\CacheSystem
\Cache\Core\System\FileCacheSystem
\Cache\Core\System\StaticArrayCacheSystem
\Cache\Core\Cache::setStateCacheSystem(CacheSystem) 
\Cache\Core\Strategy\StatefullCacheStrategy::setCacheSystem(CacheSystem)
\Cache\Core\Strategy\StatelessCacheStrategy::setCacheSystem(CacheSystem)
\Cache\Core\Cache::create



class ClasseQualquer  {

    public function gerarNroAleatorio() {
        return Cache::create(function () {
            return rand(1, 100);
        })
            ->once()        // Cacheia o valor uma única vez.
            ->statefull()   // Cache existente apenas em nivel de request.
            ->scope(false)  // Cache do método entre instâncias.
            ->ttl(10)       // Tempo do cache sera de 10 segundos.
            ->get();        // Executa a obtenção do valor
    }
}