PHP code example of marko / cache-array

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


use Marko\Cache\Contracts\CacheInterface;

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

    public function compute(string $key): array
    {
        if ($this->cache->has($key)) {
            return $this->cache->get($key);
        }

        $result = $this->doExpensiveWork($key);
        $this->cache->set($key, $result);

        return $result;
    }
}