CacheHibernate is a conservative materialized-result cache for imperative Spring Boot and Hibernate applications. A cached service invocation records the database tables read by Hibernate and remains reusable only while the logical versions of all those tables are unchanged.
The project targets Java 21+, Spring Boot 4.1, Hibernate ORM 7.4 and MySQL. Version 0.1.0-alpha.4 is experimental.
CacheHibernate is available from Maven Central. Add the Spring Boot starter to your project:
<dependency>
<groupId>io.github.bernardokcosta</groupId>
<artifactId>cache-hibernate-spring-boot-starter</artifactId>
<version>0.1.0-alpha.4</version>
</dependency>No additional Maven repository configuration is required.
See the standalone Spring Boot MySQL consumer for an executable Testcontainers example covering auto-configuration, cache hits, commit invalidation, and rollback.
- Adds a dedicated, allocation-conscious MySQL 8.x SQL analysis module without a runtime SQL AST dependency.
- Separates proven SQL effect from dependency confidence so unknown reads bypass storage and unknown effects invalidate globally.
- Handles MySQL CTEs, executable comments, multi-table DML,
ON DUPLICATE KEY UPDATE,REPLACE, andLOAD DATAwith conservative mutation semantics. - Expands
ON UPDATEandON DELETEreferential actions according to every possible mutation branch.
See MySQL SQL analysis for the safety contract and limitations, and Benchmarking for the measurement protocol.
Custom analyzer implementations and consumers of the experimental SQL SPI should read the alpha.4 migration notes.
- Result hits happen before Spring opens the target method transaction.
- Calls entered with an active transaction bypass the result cache.
- DML invalidates table versions only after commit when Spring transaction synchronization is available.
- A write without an active synchronized Spring transaction disables result caching for the process instead of risking stale publication.
- Rollback does not invalidate committed cache entries.
- A load is not published if one of its dependencies changed after that load started.
- Unknown reads are not cached; unknown writes cause global invalidation.
- Results with no observed or explicit database dependency are not cached.
- Pessimistic-lock queries, managed entities, proxies and asynchronous results are not cached.
- V1 materialized DTO graphs must use records, supported scalar values, arrays, collections, maps, optionals, or Spring Data pages; arbitrary bean getters are not cached.
Writes performed by another application, SQL script or external process are not observed in the local V1. TTL limits exposure to those writers but does not provide immediate consistency.
./mvnw verifySee Publishing to Maven Central for release prerequisites and the manual publication procedure.
GNU General Public License v3.0.