Skip to content

Query cache always missed in session having altered the entities #1730

@igitur

Description

@igitur

Refer to https://hibernate.atlassian.net/browse/HHH-5210

When using a query which is marked as cacheable, NHibernate caches both the query with the session timestamp, and its last invalidation timestamp (due to an update or save). When retrieving a query from the cache, it first compares the timestamp of the cached query with the last invalidation timestamp (UpdateTimestampsCache.IsUpToDate()):

if ((long) lastUpdate >= timestamp)
{
	return false;
}

The problem is that the timestamp for the current session, used for caching query, is always lower than invalidation's timestamp if the entities were altered in the session, even prior to caching the query and in a dedicated transaction. This causes the result of the method to be always false, discarding the cache results and hitting the database forever with that session.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions