MicroStream Reference Manual
MicroStream HomeAPI Docs
3.0
3.0
  • Preface
  • System Requirements
  • License
  • Changelog
  • Installation
  • Data-Store
    • Overview
    • Getting Started
    • Root Instances
    • Configuration
      • Properties
      • Storage Files and Directories
      • Using Channels
      • Housekeeping
      • Backup
      • Lock File
    • Storing Data
      • Convenience Methods and Explicit Storing (Transactions)
      • Lazy and Eager Storing
      • Transient Fields
      • Best Practice
    • Loading Data
      • Lazy Loading
        • Touched Timestamp, Null-Safe Variant
        • Clearing Lazy References
    • Deleting Data
    • Queries
    • Application Life-Cycle
    • Legacy Type Mapping
      • User Interaction
    • Backup Strategies
    • Import / Export
    • Housekeeping
    • Customizing
      • Custom Type Handler
      • Custom Legacy Type Handler
      • Custom Class Loader
      • Custom Storing Behavior
      • Optional Storage Manager Reference in Entities
    • REST Interface
      • Setup
      • REST API
      • Client GUI
    • FAQ
      • Data Model
      • Data Management
      • File Storage
      • Java Features
      • Miscellaneous
    • Addendum
      • Supported Java Features
      • Specialized Type Handlers
      • Examples and Demo Projects
  • Cache
    • Overview
    • Getting Started
    • Configuration
      • Properties
      • Storage
    • Use Cases
      • Hibernate Second Level Cache
      • Spring Cache
  • Basic Concepts
    • Layered Entities
      • Configuration
      • Defining Entities
      • Creating Entities
      • Updating Entities
      • Versioning
      • Logging
      • Multiple Layers
    • Wrapping
      • Configuration
      • Usage
Powered by GitBook
On this page
Export as PDF
  1. Cache
  2. Use Cases

Hibernate Second Level Cache

PreviousUse CasesNextSpring Cache

Last updated 3 years ago

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

MicroStream offers a Hibernate cache region factory, which can be found in the cache.hibernate module.

pom.xml
<repositories>
    <repository>
        <id>microstream-releases</id>
        <url>https://repo.microstream.one/repository/maven-public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>one.microstream</groupId>
        <artifactId>cache.hibernate</artifactId>
        <version>03.00.00-MS-GA</version>
    </dependency>
</dependencies>

The region factory's class name is one.microstream.cache.hibernate.CacheRegionFactory. It is configured via the property hibernate.cache.region.factory_class.

Depending on your environment it can be configured in different ways.

If you use a good old persistence.xml, set the property there:

persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
	xmlns="http://xmlns.jcp.org/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
	<persistence-unit name="...">
		<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
		...
		<properties>
			...
			<property name="hibernate.cache.region.factory_class"
				value="one.microstream.cache.hibernate.CacheRegionFactory" />
			...
		</properties>
	</persistence-unit>
</persistence>

Or for Spring applications:

spring.jpa.properties.hibernate.cache.microstream.missing_cache_strategy=create
spring.jpa.properties.hibernate.cache.region.factory_class=one.microstream.cache.hibernate.CacheRegionFactory
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.javax.persistence.sharedCache.mode=ALL

spring:
    jpa:
        properties:
            hibernate:
                cache:
                    microstream:
                        missing_cache_strategy: create
                    region:
                        factory_class: one.microstream.cache.hibernate.CacheRegionFactory
                    use_query_cache: true
                    use_second_level_cache: true
            javax:
                persistence:
                    sharedCache:
                        mode: ALL
https://docs.microstream.one/