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

[Cache] Cache::MODE_REFRESH not refereshing data #11836

Open
petrisorciprian-vitals opened this issue Feb 14, 2025 · 0 comments
Open

[Cache] Cache::MODE_REFRESH not refereshing data #11836

petrisorciprian-vitals opened this issue Feb 14, 2025 · 0 comments

Comments

@petrisorciprian-vitals
Copy link

Bug Report

Q A
Version 3.2.2, 2.20.2, probably all since introduction
Previous Version if the bug is a regression -

Summary

I'm using a decorator on top of the DefaultQueryCache implementation so that I can control the cacheMode used by Doctrine, as it defaults to Cache::MODE_NORMAL without possibility of change.

The issue I am encountering is that the DefaultQueryCache implementation does not behave as expected with Cache::MODE_REFRESH.
According to the code comments and documentation:

    /**
     * The query will never read items from the cache,
     * but will refresh items to the cache as it reads them from the database.
     */
    public const MODE_REFRESH = 4;

https://www.doctrine-project.org/projects/doctrine-orm/en/3.3/reference/second-level-cache.html#cache-mode

Current behavior

The DefaultQueryCache implementation does not refresh items into the cache when cacheMode is REFRESH.

Expected behavior

The DefaultQueryCache verifies if an item exists in the cache and, if it does, and cacheMode is REFRESH, it refreshes the value in the cache.

How to reproduce

Invoke the DefaultQueryCache::put method with a QueryCacheKey that has the cacheMode attribute set to Cache::MODE_REFRESH.

The put implementation exists early, on the following check: https://github.com/doctrine/orm/blob/3.3.x/src/Cache/DefaultQueryCache.php#L218-L220
No data is refreshed into the cache.

Side Note

As a side note, it would be nice if the cacheMode was more easily configurable. A potential way to do this would be to have the QueryCache interface defined a method, e.g. getQueryCacheKey, which would create the QueryCacheKey instance, offering an opportunity for customization of the QueryCacheKey::cacheMode attribute.

Right now, in my decorator, I basically create a new QueryCacheKey instead, and pass that along to the DefaultQueryCache implementation to achieve this, and, as far as I can tell, this is the only method available to customize the cacheMode, even though it seems to be a public API and is present in the documentation.

I'd be willing to submit a PR for this, if it is agreed upon.

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