orm
                                
                                
                                
                                    orm copied to clipboard
                            
                            
                            
                        [Cache] Cache::MODE_REFRESH not refereshing data
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 exits early, on the following check: https://github.com/doctrine/orm/blob/36bef3f959ea9f7f3ea370faf2c803b9be40f5d2/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 define 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.