Passed
Push — master ( 7de0d5...041459 )
by Pauli
13:50
created

LocalCacheTrait::invalidateCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Pauli Järvinen <[email protected]>
10
 * @copyright Pauli Järvinen 2025
11
 */
12
13
namespace OCA\Music\Utility;
14
15
/**
16
 * @phpstan-template CachedType
17
 */
18
trait LocalCacheTrait {
19
20
	/** @phpstan-var array<string, array<string, CachedType>> $localCache */
21
	protected array $localCache = [];
22
23
	/**
24
	 * @phpstan-param callable():CachedType $createItem
25
	 * @phpstan-return CachedType
26
	 */
27
	protected function cachedGet(string $userId, ?string $key, callable $createItem) {
28
		return $this->localCache[$userId][$key] ?? $this->localCache[$userId][$key] = $createItem();
29
	}
30
31
	protected function invalidateCache(string $userId) : void {
32
		unset($this->localCache[$userId]);
33
	}
34
35
}