Skip to content

Commit

Permalink
minor #2410 [Icons] use dedicated cache pool (IndraGunawan)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

[Icons] use dedicated cache pool

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| Issues        | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT

based on `@stof` comment on EasyAdminBundle repository EasyCorp/EasyAdminBundle#6507 (comment)

> you should probably create a dedicated cache pool inheriting its configuration from cache.system instead of using cache.system directly. this is how core Symfony components work (allowing them to avoid having to care about conflicting keys between the caches of different component, as the key only needs to be unique inside the cache pool)

Commits
-------

62f7c03 [Icons] use dedicated cache pool
  • Loading branch information
Kocal committed Nov 29, 2024
2 parents 7bd9e0f + 62f7c03 commit 885495a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Icons/config/iconify.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

->set('.ux_icons.iconify', Iconify::class)
->args([
service('cache.system'),
service('.ux_icons.cache'),
abstract_arg('endpoint'),
service('http_client')->nullOnInvalid(),
])
Expand Down
7 changes: 6 additions & 1 deletion src/Icons/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@

return static function (ContainerConfigurator $container): void {
$container->services()
->set('.ux_icons.cache')
->parent('cache.system')
->private()
->tag('cache.pool')

->set('.ux_icons.cache_icon_registry', CacheIconRegistry::class)
->args([
service('.ux_icons.chain_registry'),
service('cache.system'),
service('.ux_icons.cache'),
])

->set('.ux_icons.local_svg_icon_registry', LocalSvgIconRegistry::class)
Expand Down
2 changes: 1 addition & 1 deletion src/Icons/src/Iconify.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function chunk(string $prefix, array $names): iterable

private function sets(): \ArrayObject
{
return $this->sets ??= $this->cache->get('ux-iconify-sets', function () {
return $this->sets ??= $this->cache->get('iconify-sets', function () {
$response = $this->http->request('GET', '/collections');

return new \ArrayObject($response->toArray());
Expand Down
2 changes: 1 addition & 1 deletion src/Icons/src/Registry/CacheIconRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function get(string $name, bool $refresh = false): Icon
}

return $this->cache->get(
\sprintf('ux-icon-%s', Icon::nameToId($name)),
Icon::nameToId($name),
fn () => $this->inner->get($name),
beta: $refresh ? \INF : null,
);
Expand Down

0 comments on commit 885495a

Please sign in to comment.