PHP code example of fyennyi / async-cache-bridge-symfony

1. Go to this page and download the library: Download fyennyi/async-cache-bridge-symfony 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/ */

    

fyennyi / async-cache-bridge-symfony example snippets


// config/bundles.php
return [
    // ...
    Fyennyi\AsyncCache\Bridge\Symfony\AsyncCacheBundle::class => ['all' => true],
];

namespace App\Service;

use Fyennyi\AsyncCache\AsyncCacheManager;
use Fyennyi\AsyncCache\CacheOptions;

class WeatherService
{
    public function __construct(
        private AsyncCacheManager $cache
    ) {}

    public function getForecast(string $city): \React\Promise\PromiseInterface
    {
        return $this->cache->wrap(
            'weather_' . $city,
            fn() => $this->fetchFromApi($city),
            new CacheOptions(ttl: 300)
        );
    }

    private function fetchFromApi(string $city) { /* ... */ }
}