How do the Query/Result caches and the L1 cache work together?


ebenzacar@...
 

I've been encountering something I don't understand with the Query caches and the L1 cache.   I've tried reading the DN docs a few times, but I am still confused by the results I am seeing.

My persistence unit uses the default cache configuration, with no specific settings for the caches identified.  To my understanding then, the queryCache and the queryResult cache should be using soft references with unlimited size.  However, when I add profiling to my DB connection, I see the exact same query being executed multiple times.  For example, I will see the following query executed 4 times in a row:

exec sp_executesql N'SELECT ''izo.model.ActivePerson'' AS DN_TYPE FROM ACTIVEPERSON A0 WHERE A0.TYP = ''izo.model.ActivePerson'' AND A0.ID = @P0 UNION SELECT ''izo.model.Athlete'' AS DN_TYPE FROM ATHLETE A0 WHERE A0.TYP = ''izo.model.Athlete'' AND A0.ID = @P1 UNION SELECT ''izo.model.AthleteAgent'' AS DN_TYPE FROM ATHLETEAGENT A0 WHERE A0.TYP = ''izo.model.AthleteAgent'' AND A0.ID = @P2',N'@P0 bigint,@P1 bigint,@P2 bigint',4319,4319,4319

Normally, I would have expect this query to be added to the query cache, and the result to be in the queryResult cache.  Similarly, I would also expect the retrieved object(s) to be added to the L1 cache, and used for subsequent retrievals.

Questions:
1) Is the L1 cache only used if retrieving objects by Identity?
2) How does the query cache work?  What makes a query cacheable?  
3) Why would the query/result cache not be responding instead of re-querying the DB multiple times?


Thanks,

Eric

Join main@datanucleus.groups.io to automatically receive all group messages.