mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Allow changing the CacheMode when using 2nd level cache
#7403
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @petrisorciprian-vitals on GitHub (Aug 8, 2024).
Feature Request
Summary
The query cache mode using in L2 cache is defined in-line, when constructing the QueryCacheKey:
https://github.com/doctrine/orm/blob/3.2.x/src/Cache/Persister/Entity/AbstractEntityPersister.php#L305
https://github.com/doctrine/orm/blob/3.2.x/src/Cache/Persister/Entity/AbstractEntityPersister.php#L344
https://github.com/doctrine/orm/blob/3.2.x/src/Cache/Persister/Entity/AbstractEntityPersister.php#L436
This is hinted in the documentation and is a useful concept for controlling how the cache is being used, here:
https://www.doctrine-project.org/projects/doctrine-orm/en/3.2/reference/second-level-cache.html#cache-mode
However, this only works in context of AbstractQuery and QueryBuilder, it is not directly modifiable for queries such as
$this->repository->findBy(<>), which use a hardcoded cache mode value ofCacheMode::NORMAL.My use case: I am remotely controlling the cache mode for my application, and would like L2 cache to be responsive of this too, not just queries issue via
AbstractQueryorQueryBuilder.To achieve this, I would like to roll my own 2nd level CacheFactory, which is allowed by the Doctrine Bundle for Symfony via
orm.entity_managers.default.second_level_cache.factory, and decorate theEntityPersisterscreated by the factory.Then, if the CachedPersister interface would expose a setter and getter for the 'cacheMode', and the AbstractEntityPersister used the getter when constructing the QueryCacheKey instead of hard-coding the cache mode, it would also be possible to control the caching mode for L2 cache.
So, in summary, this would require:
CachedPersister,getCacheModeandsetCacheModegetCacheModeinstead of hard-coding the value toCacheMode::NORMALat all timesI can raise a PR with this change, provided a maintainer reviews this idea and approves of it.
Thank you!