Skip to content

Commit 3bf05f6

Browse files
committed
cache factory
1 parent e2aa392 commit 3bf05f6

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/Core/Factory/CacheFactory.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public static function createCachePool(
5151
string $storage,
5252
string|ObjectBuilderDefinition $serializer,
5353
string|\UnitEnum|null|false $tagStorage = false,
54+
?string $group = null,
55+
?int $defaultTtl = null,
56+
string $className = CachePool::class,
5457
) {
5558
return #[Factory]
5659
static function (
@@ -60,15 +63,20 @@ static function (
6063
$storage,
6164
$serializer,
6265
$tagStorage,
66+
$className,
67+
$defaultTtl,
6368
): CachePool {
69+
$tag = $group ?? $tag;
70+
6471
if ($tagStorage !== false && $tagStorage !== null) {
6572
$tagStorage = $container->get(StorageInterface::class, tag: $tagStorage);
6673
}
6774

68-
return new CachePool(
75+
return new $className(
6976
$container->resolve(StorageInterface::class, ['cacheTag' => $tag], tag: $storage),
7077
$container->resolve($serializer),
7178
$container->get(LoggerInterface::class, tag: 'cache'),
79+
defaultTtl: $defaultTtl,
7280
tagPool: $tagStorage
7381
);
7482
};
@@ -108,7 +116,9 @@ public static function dbStorage(
108116
public static function cachePoolFactory(
109117
string $storage,
110118
string|ObjectBuilderDefinition $serializer,
119+
string|\UnitEnum|null|false $tagStorage = false,
111120
?string $group = null,
121+
?int $defaultTtl = null,
112122
string $className = CachePool::class,
113123
): \Closure {
114124
return #[Factory]
@@ -119,12 +129,22 @@ static function (
119129
$storage,
120130
$serializer,
121131
$group,
132+
$tagStorage,
133+
$className,
134+
$defaultTtl,
122135
): CachePool {
123136
$cacheTag = $group ?? $instanceName;
137+
138+
if ($tagStorage !== false && $tagStorage !== null) {
139+
$tagStorage = $container->get(StorageInterface::class, tag: $tagStorage);
140+
}
141+
124142
return new $className(
125143
$container->resolve('cache.factories.storages.' . $storage, compact('instanceName', 'cacheTag')),
126144
$container->resolve($serializer),
127-
$container->get(LoggerInterface::class, tag: 'error')
145+
$container->get(LoggerInterface::class, tag: 'error'),
146+
defaultTtl: $defaultTtl,
147+
tagPool: $tagStorage,
128148
);
129149
};
130150
}

0 commit comments

Comments
 (0)