1 | <?php |
||
12 | abstract class CachePoolThrottle implements Throttle |
||
13 | { |
||
14 | /** |
||
15 | * @var CacheItemPoolInterface |
||
16 | */ |
||
17 | private $cacheItemPool; |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $limit; |
||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | private $perXSeconds; |
||
26 | |||
27 | /** |
||
28 | * CachePoolThrottle constructor. |
||
29 | * @param CacheItemPoolInterface $cacheItemPool |
||
30 | * @param int $limit |
||
31 | * @param int $perXSeconds |
||
32 | */ |
||
33 | 15 | public function __construct(CacheItemPoolInterface $cacheItemPool, int $limit = 60, int $perXSeconds = 60) |
|
39 | |||
40 | /** |
||
41 | * Returns true if the given request should be throttled in our implementation |
||
42 | * @param \LunixREST\Server\APIRequest\APIRequest $request |
||
43 | * @return bool |
||
44 | */ |
||
45 | 9 | public function shouldThrottle(APIRequest $request): bool |
|
51 | |||
52 | /** |
||
53 | * Log that a request took place |
||
54 | * @param \LunixREST\Server\APIRequest\APIRequest $request |
||
55 | */ |
||
56 | 4 | public function logRequest(APIRequest $request): void |
|
68 | |||
69 | /** |
||
70 | * @param APIRequest $request |
||
71 | * @return string |
||
72 | */ |
||
73 | protected abstract function deriveCacheKey(APIRequest $request): string; |
||
74 | |||
75 | /** |
||
76 | * @return CacheItemPoolInterface |
||
77 | */ |
||
78 | 2 | public function getCacheItemPool(): CacheItemPoolInterface |
|
82 | } |
||
83 |