Skip to content

Commit e72d0ae

Browse files
committed
even more jdoc about query cache invalidation
1 parent 1d5c0a6 commit e72d0ae

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

hibernate-core/src/main/java/org/hibernate/cache/spi/QueryKey.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717

1818
/**
1919
* A key that identifies a particular query with bound parameter values.
20-
* This is the object Hibernate uses as a key into its query cache.
20+
* This object is used as a key into the {@linkplain QueryResultsCache
21+
* query results cache}.
22+
* <p>
23+
* Note that the fields of this object must contain every explicit and
24+
* implicit setting and parameter argument that affects the result list
25+
* of the query, including things like the {@link #maxRows limit} and
26+
* {@link #firstRow offset}, {@link #tenantIdentifier current tenant id},
27+
* and {@link #enabledFilterNames enabled filters}.
2128
*
2229
* @author Gavin King
2330
* @author Steve Ebersole

hibernate-core/src/main/java/org/hibernate/cache/spi/QueryResultsCache.java

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1515

1616
/**
17-
* Defines the responsibility for managing query result data caching
18-
* in a specific {@linkplain QueryResultsRegion query cache region}.
19-
* There may be multiple instances of {@code QueryResultsCache},
20-
* corresponding to second-level cache regions with distinct policies.
17+
* Responsible for managing query result list caching in a specific
18+
* {@linkplain QueryResultsRegion query cache region}. There may be
19+
* multiple instances of {@code QueryResultsCache}, corresponding to
20+
* second-level cache regions with distinct policies.
2121
* <p>
22-
* A {@code QueryResultsCache} must be used in conjunction with a
23-
* {@link TimestampsCache} which tracks invalidation of the query
24-
* spaces (tables) which affect the cached queries.
22+
* A {@code QueryResultsCache} depends on the {@link TimestampsCache}
23+
* to track invalidation of the query spaces (tables) which affect the
24+
* cached queries. A cached query result list is considered <em>stale</em>
25+
* if any one of the query spaces which affect the query results was
26+
* {@linkplain TimestampsCache#invalidate invalidated} since the result
27+
* list was read from the database and {@linkplain #put stored} in the
28+
* query result cache.
2529
*
2630
* @author Gavin King
2731
* @author Steve Ebersole
@@ -33,10 +37,12 @@ public interface QueryResultsCache {
3337
QueryResultsRegion getRegion();
3438

3539
/**
36-
* Put a result into the query cache.
40+
* Store a result list of a query with the given {@link QueryKey}
41+
* in the query result cache.
3742
*
38-
* @param key The cache key
39-
* @param result The results to cache
43+
* @param key The cache key uniquely identifying the query and its
44+
* bound parameter arguments
45+
* @param result The result list to cache
4046
* @param session The originating session
4147
*
4248
* @return Whether the put actually happened.
@@ -49,13 +55,21 @@ boolean put(
4955
SharedSessionContractImplementor session) throws HibernateException;
5056

5157
/**
52-
* Get results from the cache.
58+
* Attempt to retrieve a cached query result list for the given
59+
* {@link QueryKey} from the {@linkplain QueryResultsRegion cache
60+
* region}, and then {@linkplain TimestampsCache#isUpToDate check}
61+
* if the cached results, if any, are stale. If there is no cached
62+
* result list for the given key, or if the cached results are stale,
63+
* return {@code null}.
5364
*
54-
* @param key The cache key
55-
* @param spaces The query spaces (used in invalidation plus validation checks)
65+
* @param key The cache key uniquely identifying the query and its
66+
* bound parameter arguments
67+
* @param spaces The query spaces which affect the results of the
68+
* query (used to check if cached results are stale)
5669
* @param session The originating session
5770
*
58-
* @return The cached results; may be null.
71+
* @return The cached results; may be null if there are no cached
72+
* results for the given key, or if the results are stale.
5973
*
6074
* @throws HibernateException Indicates a problem delegating to the underlying cache.
6175
*/
@@ -65,10 +79,17 @@ List<?> get(
6579
SharedSessionContractImplementor session) throws HibernateException;
6680

6781
/**
68-
* Get results from the cache.
82+
* Attempt to retrieve a cached query result list for the given
83+
* {@link QueryKey} from the {@linkplain QueryResultsRegion cache
84+
* region}, and then {@linkplain TimestampsCache#isUpToDate check}
85+
* if the cached results, if any, are stale. If there is no cached
86+
* result list for the given key, or if the cached results are stale,
87+
* return {@code null}.
6988
*
70-
* @param key The cache key
71-
* @param spaces The query spaces (used in invalidation plus validation checks)
89+
* @param key The cache key uniquely identifying the query and its
90+
* bound parameter arguments
91+
* @param spaces The query spaces which affect the results of the
92+
* query (used to check if cached results are stale)
7293
* @param session The originating session
7394
*
7495
* @return The cached results; may be null.
@@ -81,7 +102,7 @@ List<?> get(
81102
SharedSessionContractImplementor session) throws HibernateException;
82103

83104
/**
84-
* Clear items from the query cache.
105+
* Clear all items from this query result cache.
85106
*
86107
* @throws CacheException Indicates a problem delegating to the underlying cache.
87108
*/
@@ -90,6 +111,6 @@ default void clear() throws CacheException {
90111
}
91112

92113
default void destroy() {
93-
// nothing to do.. the region itself gets destroyed
114+
// nothing to do, the region itself gets destroyed
94115
}
95116
}

hibernate-core/src/main/java/org/hibernate/cache/spi/TimestampsCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Hibernate affects the corresponding table.
2323
* <li>A cached query result set is {@linkplain #isUpToDate checked for
2424
* staleness} against the {@code TimestampsCache} when it is read
25-
* from the {@link QueryResultsCache}.
25+
* from a {@link QueryResultsRegion} by a {@link QueryResultsCache}.
2626
* </ul>
2727
*
2828
* @author Steve Ebersole

0 commit comments

Comments
 (0)