PHP code example of phpyh / lru-memoizer

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

    

phpyh / lru-memoizer example snippets


use PHPyh\LRUMemoizer\LRUMemoizer;

final class Metadata {}

final class MetadataFactory
{
    public function __construct(
        private readonly LRUMemoizer $memoizer = new LRUMemoizer(capacity: 25),
    ) {
    }

    /**
     * @param ?class-string $class
     */
    public function metadataFor(string $class): Metadata
    {
        return $this->memoizer->get($class, static fn (): Metadata => new Metadata());
    }
}