Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
77.78% |
7 / 9 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| StatusCacheService | |
77.78% |
7 / 9 |
|
50.00% |
2 / 4 |
7.54 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setStatus | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| invalidateStatus | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getStatus | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\SignRequest; |
| 10 | |
| 11 | use OCP\ICache; |
| 12 | use OCP\ICacheFactory; |
| 13 | |
| 14 | class StatusCacheService { |
| 15 | public const STATUS_KEY_PREFIX = 'libresign_status_'; |
| 16 | public const DEFAULT_TTL = 300; |
| 17 | |
| 18 | private ICache $cache; |
| 19 | |
| 20 | public function __construct( |
| 21 | ICacheFactory $cacheFactory, |
| 22 | ) { |
| 23 | $this->cache = $cacheFactory->createDistributed('libresign_progress'); |
| 24 | } |
| 25 | |
| 26 | public function setStatus(string $fileUuid, int $status): void { |
| 27 | |
| 28 | if ($fileUuid === '') { |
| 29 | return; |
| 30 | } |
| 31 | $this->cache->set(self::STATUS_KEY_PREFIX . $fileUuid, $status, self::DEFAULT_TTL); |
| 32 | } |
| 33 | |
| 34 | /** Discard stale status hints without overwriting a worker's result. */ |
| 35 | public function invalidateStatus(string $fileUuid): void { |
| 36 | if ($fileUuid !== '') { |
| 37 | $this->cache->remove(self::STATUS_KEY_PREFIX . $fileUuid); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public function getStatus(string $fileUuid): mixed { |
| 42 | if ($fileUuid === '') { |
| 43 | return false; |
| 44 | } |
| 45 | return $this->cache->get(self::STATUS_KEY_PREFIX . $fileUuid); |
| 46 | } |
| 47 | } |