PHP code example of marko / cache-redis

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

    

marko / cache-redis example snippets


use Marko\Cache\Contracts\CacheInterface;

class SessionStore
{
    public function __construct(
        private CacheInterface $cache,
    ) {}

    public function getSession(string $token): ?array
    {
        return $this->cache->get("session.$token");
    }

    public function saveSession(string $token, array $data): void
    {
        $this->cache->set("session.$token", $data, ttl: 1800);
    }
}