Skip to content

Commit cab099c

Browse files
ljacometsebersole
authored andcommitted
HHH-10770 JCache provider documentation
1 parent 2ddefd6 commit cab099c

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

documentation/src/main/asciidoc/quickstart/guides/obtaining.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ hibernate-osgi:: Hibernate support for running in OSGi containers.
1414
hibernate-c3p0:: Integrates the link:$$http://www.mchange.com/projects/c3p0/$$[C3P0] connection pooling library into Hibernate
1515
hibernate-hikaricp:: Integrates the link:$$http://brettwooldridge.github.io/HikariCP/$$[HikariCP] connection pooling library into Hibernate
1616
hibernate-proxool:: Integrates the link:$$http://proxool.sourceforge.net/$$[Proxool] connection pooling library into Hibernate
17+
hibernate-jcache:: Integrates the link:$$https://jcp.org/en/jsr/detail?id=107$$[JCache] caching specification into Hibernate,
18+
enabling any compliant implementation to become a second-level cache provider.
1719
hibernate-ehcache:: Integrates the link:$$http://ehcache.org/$$[Ehcache] caching library into Hibernate as a second-level cache provider.
1820
hibernate-infinispan:: Integrates the link:$$http://infinispan.org/$$[Infinispan] caching library into Hibernate as a second-level cache provider.
1921

documentation/src/main/asciidoc/userguide/chapters/caching/Caching.adoc

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ This section defines the settings which control this behavior.
2525

2626
`org.hibernate.cache.spi.RegionFactory` defines the integration between Hibernate and a pluggable caching provider.
2727
`hibernate.cache.region.factory_class` is used to declare the provider to use.
28-
Hibernate comes with built-in support for two popular caching libraries: <<caching-provider-ehcache,Ehcache>> and <<caching-provider-infinispan,Infinispan>>.
28+
Hibernate comes with built-in support for the Java caching standard <<caching-provider-jcache,JCache>>
29+
and also two popular caching libraries: <<caching-provider-ehcache,Ehcache>> and <<caching-provider-infinispan,Infinispan>>.
2930
Detailed information is provided later in this chapter.
3031

3132
[[caching-config-properties]]
@@ -462,10 +463,68 @@ include::{sourcedir}/SecondLevelCacheTest.java[tags=caching-statistics-example]
462463
----
463464
====
464465

466+
[[caching-provider-jcache]]
467+
=== JCache
468+
469+
[NOTE]
470+
====
471+
Use of the build-in integration for https://jcp.org/en/jsr/detail?id=107[JCache] requires that the `hibernate-jcache` module jar (and all of its dependencies) are on the classpath.
472+
In addition a JCache implementation needs to be added as well.
473+
A list of compatible implementations can be found https://jcp.org/aboutJava/communityprocess/implementations/jsr107/index.html[on the JCP website].
474+
An alternative source of compatible implementations can be found through https://github.com/cruftex/jsr107-test-zoo[the JSR-107 test zoo].
475+
====
476+
477+
[[caching-provider-jcache-region-factory]]
478+
==== RegionFactory
479+
480+
The `hibernate-jcache` module defines the following region factory: `JCacheRegionFactory`.
481+
482+
To use the `JCacheRegionFactory`, you need to specify the following configuration property:
483+
484+
[[caching-provider-jcache-region-factory-example]]
485+
.`JCacheRegionFactory` configuration
486+
====
487+
[source, XML, indent=0]
488+
----
489+
<property
490+
name="hibernate.cache.region.factory_class"
491+
value="org.hibernate.cache.jcache.JCacheRegionFactory"/>
492+
----
493+
====
494+
495+
The `JCacheRegionFactory` configures a `javax.cache.CacheManager`.
496+
497+
[[caching-provider-jcache-cache-manager]]
498+
==== JCache `CacheManager`
499+
500+
JCache mandates that `CacheManager`{empty}s sharing the same URI and class loader be unique in JVM.
501+
502+
If you do not specify additional properties, the `JCacheRegionFactory` will load the default JCache provider and create the default `CacheManager`.
503+
Also, `Cache`{empty}s will be created using the default `javax.cache.configuration.MutableConfiguration`.
504+
505+
In order to control which provider to use and specify configuration for the `CacheManager` and `Cache`{empty}s you can use the following two properties:
506+
507+
[[caching-provider-jcache-region-factory-config-example]]
508+
.JCache configuration
509+
====
510+
[source, XML, indent=0]
511+
----
512+
<property
513+
name="hibernate.javax.cache.provider"
514+
value="org.ehcache.jsr107.EhcacheCachingProvider"/>
515+
<property
516+
name="hibernate.javax.cache.uri"
517+
value="file:/path/to/ehcache.xml"/>
518+
----
519+
====
520+
521+
Only by specifying the second property `hibernate.javax.cache.uri` will you be able to have a `CacheManager` per `SessionFactory`.
465522

466523
[[caching-provider-ehcache]]
467524
=== Ehcache
468525

526+
This integration covers Ehcache 2.x, in order to use Ehcache 3.x as second level cache, refer to the <<caching-provider-jcache,JCache integration>>.
527+
469528
[NOTE]
470529
====
471530
Use of the build-in integration for http://www.ehcache.org/[Ehcache] requires that the `hibernate-ehcache` module jar (and all of its dependencies) are on the classpath.

0 commit comments

Comments
 (0)