Skip to content

SQL query result not retrieved from second level cache #2904

Closed
@petertownsend

Description

@petertownsend

NHibernate: Version="5.3.9"
NHibernate.Caches.CoreMemoryCache: Version="5.7.0"

Problem

The second level cache is failing to match existing entries when with the CoreMemoryCache - this seems to be down to the ResultTransformer being included in the QueryKey equality and for SQL queries this gets updated to be a CacheableResultTransformer. The equality then fails with the next identical query due to the CacheableResultTransformer.

Example of query below, with 2nd level cache enabled.

query = session.CreateSQLQuery("replace this with a simple select returning a single value");
query.SetCacheable(true);
query.List(); 

##Work Around
Implementing my own CoreMemoryCache that doesn't use the QueryKey object directly works:

if (!(key is QueryKey queryKey)) return new Tuple<string, object>(_fullRegion, key);
            return new Tuple<string, object>(_fullRegion, queryKey.ToString()); // Fix for unequal QueryKey due to CacheableResultTransformer

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions