1414import 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}
0 commit comments