PHP code example of juanchosl / simplecache

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

    

juanchosl / simplecache example snippets


use JuanchoSL\SimpleCache\Repositories\ProcessCache;

$cache = new ProcessCache($_ENV['CACHE_ENVIRONMENT']);
//The max time to expire is 30 days if you do not set a time
$cache->setMaxTtl(3600 * 24);

$result = $cache->set(string $cache_key, mixed $value, int $ttl = 0);

$cache_value = $cache->get(string $cache_key, $default = null);

$result = $cache->delete(string $cache_key);

$result = $cache->setMultiple(iterable $values, \DateInterval|int $ttl = 0);

$cache_value = $cache->getMultiple(iterable $cache_keys, $default = null);

$result = $cache->deleteMultiple(iterable $cache_keys);

$result = $cache->replace(string $cache_key, mixed $new_value);

$result = $cache->touch(string $cache_key, \DateInterval|int $new_ttl);

$result = $cache->increment(string $cache_key, int|float $numeric_increment, \DateInterval|int $ttl_if_not_exists = $max_ttl);

$result = $cache->decrement(string $cache_key, int|float $numeric_decrement, \DateInterval|int $ttl_if_not_exists = $max_ttl);

$result = $cache->has(string $cache_key);

$result = $cache->clear();

use JuanchoSL\SimpleCache\Repositories\ProcessCache;
use JuanchoSL\SimpleCache\Adapters\PsrSimpleCacheAdapter;

$lib = new ProcessCache($_ENV['CACHE_ENVIRONMENT']);
$cache = new PsrSimpleCacheAdapter($lib);