PHP code example of rnr1721 / le7-cache

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

    

rnr1721 / le7-cache example snippets



use Core\Cache\SCFactoryGeneric;

$cacheFactory = new SCFactoryGeneric();

$cache = $cacheFactory->getFileCache('./cache');

$data = [
    'value1' => 'The 1 value',
    'value2' => 'The 2 value'
    ];

// Put data in cache
// Set cache key, value and time-to-live
$cache->set('mykey', $data, 5000);

// Get value from cache
$result = $cache->get('mykey');

print_r($result);



use Psr\SimpleCache\CacheInterface;

    public function get(string $key, mixed $default = null): mixed;

    public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool;

    public function delete(string $key): bool;

    public function clear(): bool;

    public function getMultiple(iterable $keys, mixed $default = null): iterable;

    public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool;

    public function deleteMultiple(iterable $keys): bool;

    public function has(string $key): bool;



use Core\Interfaces\SCFactory;

    /**
     * Get filesysyem cache
     * @param string $folder Folder for caache
     * @return CacheInterface
     */
    public function getFileCache(string $folder): CacheInterface;

    /**
     * Get memory cache
     * @return CacheInterface
     */
    Public function getMemory(): CacheInterface;

    /**
     * Get Session cache
     * @return CacheInterface
     */
    public function getSession(): CacheInterface;