Skip to content

Commit 314c434

Browse files
Merge pull request #4 from code-q-web-factory/FEATURE/requests-cache
FEATURE: Add request cache
2 parents 103e5ad + 8c4d101 commit 314c434

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

Classes/Domain/Service/ZoomApiService.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class ZoomApiService
2626
*/
2727
protected array $settings;
2828

29+
/**
30+
* @var VariableFrontend
31+
*/
32+
protected $requestsCache;
33+
2934
/**
3035
* @throws Exception
3136
*/
@@ -62,10 +67,19 @@ private function generateJwt(string $zoomApiKey, string $zoomApiSecret): string
6267
*/
6368
public function getUpcomingMeetings(): array
6469
{
65-
return $this->fetchData(
70+
$cacheEntryIdentifier = 'upcomingMeetings';
71+
72+
/** @var array|bool $upcomingMeetings */
73+
if (($upcomingMeetings = $this->requestsCache->get($cacheEntryIdentifier)) !== false) {
74+
return $upcomingMeetings;
75+
}
76+
77+
$upcomingMeetings = $this->fetchData(
6678
"users/me/meetings?type=upcoming",
6779
'meetings'
6880
);
81+
$this->requestsCache->set($cacheEntryIdentifier, $upcomingMeetings);
82+
return $upcomingMeetings;
6983
}
7084

7185
/**
@@ -78,6 +92,13 @@ public function getUpcomingMeetings(): array
7892
*/
7993
public function getRecordings($from, $to): array
8094
{
95+
$cacheEntryIdentifier = sprintf('recordings_%s_%s', $from, $to);
96+
97+
/** @var array|bool $recordings */
98+
if (($recordings = $this->requestsCache->get($cacheEntryIdentifier)) !== false) {
99+
return $recordings;
100+
}
101+
81102
if (is_string($from)) {
82103
$from = new DateTimeImmutable($from);
83104
} elseIf ($from instanceof DateTime) {
@@ -94,7 +115,9 @@ public function getRecordings($from, $to): array
94115
throw new \InvalidArgumentException('The from date must be after the to date');
95116
}
96117

97-
return $this->fetchDataForDateRange($from, $to);
118+
$recordings = $this->fetchDataForDateRange($from, $to);
119+
$this->requestsCache->set($cacheEntryIdentifier, $recordings);
120+
return $recordings;
98121
}
99122

100123
private function fetchDataForDateRange(DateTimeImmutable $from, DateTimeImmutable $to): array

Configuration/Caches.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CodeQ_ZoomApi_Requests:
2+
frontend: Neos\Cache\Frontend\VariableFrontend
3+
backend: Neos\Cache\Backend\FileBackend
4+
backendOptions:
5+
defaultLifetime: 0

Configuration/Objects.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CodeQ\ZoomApi\Domain\Service\ZoomApiService:
2+
properties:
3+
requestsCache:
4+
object:
5+
factoryObjectName: Neos\Flow\Cache\CacheManager
6+
factoryMethodName: getCache
7+
arguments:
8+
1:
9+
value: CodeQ_ZoomApi_Requests

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ CodeQ.ZoomApi.getRecordings(Date.create('2021-01-01'), Date.now())
3434
```
3535

3636
Be aware, that this helper currently does not implement caching.
37+
38+
## Performance and Caching
39+
40+
Beware, that the package does not cache the requests by default. Thus, using these Eel helpers on
41+
heavily frequented pages can lead to rate limit issues with the Zoom API. This package provides
42+
a request cache to tackle that issue.
43+
44+
By default, the cache is disabled. To enable the cache, configure the lifetime at your convenience:
45+
46+
```yaml
47+
CodeQ_ZoomApi_Requests:
48+
backendOptions:
49+
defaultLifetime: 600 # e.g. 60 seconds * 10 minutes = 600 seconds
50+
```
51+
52+
Of course, you can also switch to a different cache backend at your convenience.

0 commit comments

Comments
 (0)