Repository navigation
fix: cache the entity registry per filament panel - #289
Merged
Merged
Conversation
Discovery builds the registry from the current panel's resources, but the cache key was shared, so a multi-panel app served every panel the registry of whichever panel built it first. The key now carries the panel id, and the configured ttl reaches the cache.
Clears the cached entity registry of every panel, so a deploy can drop a registry built from the previous configuration.
A long-lived manager, such as a queue worker running import jobs for several panels, kept serving the first panel's registry and could write it under another panel's cache key. The manager's memo is now keyed by panel id, and discovery no longer keeps its own memo.
This was referenced Nov 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An app with more than one Filament panel can now turn on the entity cache safely. Before, the cache served every panel the registry built by whichever panel populated it first. For example, a request in a panel without a model's resource could warm the cache. Every other panel then lost that model's resource class, its title attribute (falling back to
id) and its search attributes for the full TTL. Record-lookup fields showed IDs instead of names and searched nothing. Record links could point at a resource the current panel does not register.This PR also adds
custom-fields:clear-cacheso deploys can drop a registry built from the previous configuration, and makes the configured TTL take effect.What changed
EntityManager: the persistent cache key is nowcustom_fields_entities:<panel id>, taken fromFilament::getCurrentOrDefaultPanel(), withno-panelwhen no default panel exists. The in-memory memo is keyed the same way, so a long-lived manager (a queue worker running import jobs for several panels) serves each panel its own registry.EntityDiscovery: drops its owndiscoveredCachememo. It held the first panel's resources for the life of the singleton, and the manager's per-panel memo already prevents rebuilds.EntityServiceProviderpassescache_ttlfromEntityConfigurator::cache($enabled, $ttl)intoEntityManager. Before, the value was read and dropped, and a hardcoded 3600 applied.custom-fields:clear-cache(ClearCacheCommand): forgets the registry key of every registered panel plusno-panel. It does nothing when caching is off.essentials/configuration): the performance section shows the TTL and the deploy-time clear.Why this way
The registry is per panel by nature.
EntityDiscovery::discoverFromFilamentResources()andEntityConfigurationData::resolveIconFromFilamentResource()readFilament::getResources()of the current panel.RecordColumnandRecordEntrythen build links with$resourceClass::getUrl(). A single panel-independent registry would hand one panel links to resources it does not register, so keying by panel keeps the current per-panel behaviour and just caches it.The command is not hooked into
optimizeoroptimize:clear. A build step that runsoptimizewithout the cache store reachable would fail. Apps add it to their deploy commands instead.Behavior to know about
custom_fields_entitieskey is never read again and expires within its TTL.FieldTypeConfigurator::cache()is untouched. Nothing reads its values today, but removing the method would break every config file that calls it.Upgrade\Steps\ClearCachesStepstill forgets an old key name (custom-fields:entity-registry). It runs right aftercache:clear, so it has no effect either way, and this PR leaves it alone.Tests
tests/Feature/EntityRegistryCacheTest.phpregisters a second panel withoutPostResource:custom-fields:clear-cacheremoves both panels' keys, which the test confirms exist first.All four fail on
3.xand pass here.Checked
On
baaed3d5:vendor/bin/pest --parallel: 1127 passed, 3 todo. PHPStan reports no errors; Rector and Pint pass.name, two search attributes. Switching panels inside one process gave each panel its own registry. A warm cached read took 2.3 ms; the uncached build takes about 21 ms there.custom-fields:clear-cacheremoved every panel's key.Not checked
4.xhas the same code at these lines and needs the same change in a separate PR.