Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing the CacheMode when using 2nd level cache #11566

Open
petrisorciprian-vitals opened this issue Aug 8, 2024 · 0 comments
Open

Comments

@petrisorciprian-vitals
Copy link

petrisorciprian-vitals commented Aug 8, 2024

Feature Request

Q A
New Feature yes
RFC no
BC Break no

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 of CacheMode::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 AbstractQuery or QueryBuilder.

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 the EntityPersisters created 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:

  • two new interface methods for the CachedPersister, getCacheMode and setCacheMode
  • changing the AbstractEntityPersister to use getCacheMode instead of hard-coding the value to CacheMode::NORMAL at all times

I can raise a PR with this change, provided a maintainer reviews this idea and approves of it.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant