-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathusnig-cache.php
27 lines (21 loc) · 1.01 KB
/
usnig-cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use MaciejSz\Nbp\Service\GoldRatesService;
use MaciejSz\Nbp\Shared\Infrastructure\Client\NbpWebClient;
use MaciejSz\Nbp\Shared\Infrastructure\Repository\NbpWebRepository;
use MaciejSz\Nbp\Shared\Infrastructure\Transport\CachingTransportFactory;
use Symfony\Component\Cache\Adapter\FilesystemAdapter as CachePoolAdapter;
// 1) create repository backed by caching transport
$cachePool = new CachePoolAdapter();
$cachingTransportFactory = CachingTransportFactory::new($cachePool);
$client = NbpWebClient::new(transportFactory: $cachingTransportFactory);
$nbpRepository = NbpWebRepository::new($client);
// 2) create needed services using cache-backed repository:
$goldRates = new GoldRatesService($nbpRepository);
// 3) run multiple times to check the effect of caching:
$start = microtime(true);
$goldRates->fromDayBefore('2013-05-15')->getValue();
$end = microtime(true);
$took = $end - $start;
printf('Getting the rate took %F ms', $took * 1000);