forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractCacheFactory.php
More file actions
61 lines (52 loc) · 1.69 KB
/
AbstractCacheFactory.php
File metadata and controls
61 lines (52 loc) · 1.69 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace ProcessMaker\Cache;
use Illuminate\Cache\CacheManager;
use ProcessMaker\Cache\Monitoring\CacheMetricsDecorator;
use ProcessMaker\Cache\Monitoring\CacheMetricsInterface;
use ProcessMaker\Cache\Monitoring\PrometheusMetricsManager;
abstract class AbstractCacheFactory implements CacheFactoryInterface
{
protected static ?CacheInterface $testInstance = null;
/**
* Set a test instance for the factory
*
* @param CacheInterface|null $instance
*/
public static function setTestInstance(?CacheInterface $instance): void
{
static::$testInstance = $instance;
}
/**
* Create a new cache instance with metrics monitoring
*
* @param CacheManager $cacheManager
* @param CacheMetricsInterface $metrics
* @return CacheInterface
*/
public static function create(CacheManager $cacheManager, CacheMetricsInterface $metrics): CacheInterface
{
if (static::$testInstance !== null) {
return static::$testInstance;
}
// Create base cache instance
$cache = static::createInstance($cacheManager);
// Wrap with metrics decorator
return new CacheMetricsDecorator($cache, $metrics);
}
/**
* Get the current cache instance
*
* @return CacheInterface
*/
protected static function getInstance(): CacheInterface
{
return static::create(app('cache'), app()->make(PrometheusMetricsManager::class));
}
/**
* Create the specific cache instance
*
* @param CacheManager $cacheManager
* @return CacheInterface
*/
abstract protected static function createInstance(CacheManager $cacheManager): CacheInterface;
}