Skip to content

Commit 34f7a4d

Browse files
committed
talk about impact of external updates on cached data
1 parent 92de056 commit 34f7a4d

File tree

1 file changed

+16
-3
lines changed
  • documentation/src/main/asciidoc/introduction

1 file changed

+16
-3
lines changed

documentation/src/main/asciidoc/introduction/Tuning.adoc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ Therefore, by default, an entity is not eligible for storage in the second-level
410410
We must explicitly mark each entity that will be stored in the second-level cache with the link:{doc-javadoc-url}/org/hibernate/annotations/Cache.html[`@Cache`] annotation from `org.hibernate.annotations`.
411411

412412
But that's still not enough.
413-
Hibernate does not itself contain an implementation of a second-level cache, so it's necessary to configure an external _cache provider_.
413+
Hibernate does not itself contain an implementation of a second-level cache, so it's also necessary to configure an external _cache provider_.
414414

415415
[CAUTION]
416416
// .Caching is disabled by default
@@ -430,6 +430,14 @@ Each region is permitted its own policies for expiry, persistence, and replicati
430430

431431
The appropriate policies depend on the kind of data an entity represents. For example, a program might have different caching policies for "reference" data, for transactional data, and for data used for analytics. Ordinarily, the implementation of those policies is the responsibility of the underlying cache implementation.
432432

433+
[WARNING]
434+
====
435+
The second-level cache is never aware of any changes to data which are made externally to Hibernate.
436+
Updates made via direct JDBC--or by some other program--are never visible in the second-level cache.
437+
When such updates occur, we might need to <<second-level-cache-management,explicitly invalidate cached data>>.
438+
Alternatively, in cases where the program is able to tolerate somewhat stale data, an expiry policy might be an acceptable solution.
439+
====
440+
433441
[[enable-second-level-cache]]
434442
=== Specifying which data is cached
435443

@@ -850,8 +858,13 @@ sessionFactory.inSession(session -> {
850858
----
851859
====
852860

853-
Very occasionally, it's necessary or advantageous to control the cache explicitly, for example, to evict some data that we know to be stale.
854-
The `Cache` interface allows programmatic eviction of cached items.
861+
Very occasionally, it's necessary or advantageous to control the cache explicitly.
862+
For example, we might need to evict some data that we know to be stale because it was updated:
863+
864+
- via direct JDBC, or
865+
- by some other program.
866+
867+
The link:{doc-javadoc-url}org/hibernate/Cache.html[`Cache`] interface allows programmatic eviction of cached items.
855868

856869
[source,java]
857870
----

0 commit comments

Comments
 (0)