Compile-time generated, Redis-first active-data persistence and read models for Java 21 & Spring Boot — backed by PostgreSQL, SQL Server, or Oracle Database.
English | Türkçe
Why CacheDB · 5-Minute Quick Start · Core Concepts · Key Features · Runnable Samples · Documentation
Most high-throughput backends eventually outgrow putting ad-hoc @Cacheable annotations or handwritten Redis hashes in front of a relational database. Unbounded caches drift from SQL, blow up memory, or collapse under relation N+1 storms.
CacheDB gives you ORM-like developer ergonomics with explicit, compile-time verified boundaries:
- Redis serves hot operational reads — sub-millisecond point lookups, compact projections, ranked timelines, and composite keyset cursors.
- SQL remains your durable source of truth — asynchronous, version-fenced write-behind persists mutations to PostgreSQL, SQL Server, or Oracle Database, while cold/archive queries use explicit SQL routes.
- Zero runtime reflection — a Java annotation processor (
cachedb-processor) validates entities, queries, projections, and limits at compile time and generates type-safe repositories and Jackson-free codecs. - Predictable memory & latency — hot-window policies, relation limits, payload budgets, and tenant quotas keep Redis bounded by design.
flowchart LR
App["Spring Boot / Java 21 Service"] --> Repo["@CacheRepository (Compile-Time Generated)"]
Repo -->|Hot Reads & Projections| Redis["Redis 8 / Cluster + Optional L1"]
Repo -->|Accepted Writes| Stream["Version-Fenced Write-Behind"]
Stream -->|Batched Durable Flush| SQL[("PostgreSQL / SQL Server / Oracle")]
Repo -->|Explicit @SourceRoute| SQL
When to use CacheDB: High-throughput operational APIs, storefronts, order/customer timelines, stock & catalog read models, and multi-tenant SaaS workloads where hot active data lives in Redis and full durable history lives in SQL.
When not to use CacheDB: CacheDB is not a transparent read-through cache for arbitrary dynamic SQL joins. A Redis miss does not silently scan your SQL database — cold history is queried explicitly through
@SourceRoute.
CacheDB 0.19.4 requires Java 21+ (applications still on Java 17 can use the 0.18.1 maintenance line). Packages are served directly from the public Maven repository — no GitHub token, settings.xml, or local framework build is needed.
Import cachedb-bom, select your SQL provider starter, and register cachedb-processor:
<properties>
<cachedb.version>0.19.4</cachedb.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.reactor.cachedb</groupId>
<artifactId>cachedb-bom</artifactId>
<version>${cachedb.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Choose ONE SQL provider starter: postgres, mssql, or oracle -->
<dependency>
<groupId>com.reactor.cachedb</groupId>
<artifactId>cachedb-spring-boot-starter-postgres</artifactId>
</dependency>
<dependency>
<groupId>com.reactor.cachedb</groupId>
<artifactId>cachedb-annotations</artifactId>
</dependency>
<!-- Optional: Operations Dashboard & Migration Planner UI -->
<dependency>
<groupId>com.reactor.cachedb</groupId>
<artifactId>cachedb-spring-boot-starter-admin</artifactId>
</dependency>
<!-- Add spring-boot-starter-jdbc if your app does not already define a DataSource -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.reactor.cachedb</groupId>
<artifactId>cachedb-processor</artifactId>
<version>${cachedb.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>cachedb-public</id>
<url>https://esasmer-dou.github.io/cache-database/maven2</url>
</repository>
</repositories>| SQL Database | Starter Artifact | JDBC Driver |
|---|---|---|
| PostgreSQL | cachedb-spring-boot-starter-postgres |
org.postgresql:postgresql |
| SQL Server | cachedb-spring-boot-starter-mssql |
com.microsoft.sqlserver:mssql-jdbc |
| Oracle Database | cachedb-spring-boot-starter-oracle |
com.oracle.database.jdbc:ojdbc17 (transitive) |
spring:
datasource:
url: jdbc:postgresql://127.0.0.1:5432/app
username: app
password: app
cachedb:
enabled: true
profile: production
redis:
uri: redis://127.0.0.1:6379
registration:
source: jdbc
fail-on-unknown-entity: true
entities:
CustomerEntity:
hot-entity-limit: 50000
page-size: 100
hot-policy:
mode: STATE_WINDOW
state-column: status
state-values: [ACTIVE]Persisted fields use explicit annotations and non-private, non-final visibility so generated codecs read and write them without reflection:
@CacheEntity(table = "customers", redisNamespace = "customers")
public class CustomerEntity {
@CacheId(column = "customer_id")
public Long customerId;
@CacheColumn("tax_number")
public String taxNumber;
@CacheColumn("customer_type")
public String customerType;
@CacheColumn("status")
public String status;
public CustomerEntity() {}
}cachedb-processor validates route fields, predicates, and limits at compile time and generates the Spring bean automatically:
@CacheRepository(entity = CustomerEntity.class)
public interface CustomerRepository extends CacheDbRepository<CustomerEntity, Long> {
@CacheLookup(idParameter = "customerId")
HotLookup<CustomerEntity> detail(Long customerId);
@SourceRoute(value = "customer-archive", maxRows = 100, timeoutSeconds = 10)
@CacheRouteQuery(
predicates = @CachePredicate(field = "customerType"),
orderBy = @CacheOrder(field = "customerId", direction = CacheOrder.Direction.DESC)
)
List<CustomerEntity> archiveByType(String customerType, int limit);
}Inject CustomerRepository directly into your Spring service:
@Service
public class CustomerService {
private final CustomerRepository customers;
public CustomerService(CustomerRepository customers) {
this.customers = customers;
}
public WriteReceipt<CustomerEntity, Long> register(CustomerEntity customer) {
// Writes to Redis when admitted by hot policy and enqueues durable SQL flush
return customers.save(customer);
}
public CustomerEntity getActive(long id) {
// Sub-millisecond Redis lookup; never triggers an implicit SQL scan
return customers.detail(id).orElseThrow(status ->
new ResponseStatusException(HttpStatus.NOT_FOUND, "Customer not in hot set: " + status));
}
}| Concept | How It Works in CacheDB |
|---|---|
| Hot Policy | Controls which rows live in Redis (COUNT_WINDOW for latest TIME_WINDOW for recent days, STATE_WINDOW for active states like OPEN/ACTIVE, or COMPOSITE combinations). |
Projections (@CacheProjectionRecord) |
Compact, screen-shaped Java record read models maintained in Redis for lists, timelines, and ranked top-$N$ dashboards — avoiding full object-graph hydration. |
Bounded Relations (@CacheRelation) |
Explicit, batch-loaded child previews (e.g., latest 20 orders on a customer detail page). No transparent lazy-loading proxies or hidden N+1 queries. |
| Warm & Scheduled Reconciliation |
@WarmRoute and @CacheScheduledWarm backfill Redis from SQL with dry-run previews, distributed Redis leader leases, and checkpoint progress. |
Cold / Archive Paths (@SourceRoute) |
Explicit, row-bounded, timeout-guarded SQL queries for historical exports, audits, and records outside the active Redis window. |
- Compile-Time Repositories & Codecs:
@CacheRepository,@HotRoute,@WarmRoute,@SourceRoute, and generated streaming JSON codecs with zero reflection overhead. - L1 Near Cache & Read Coalescing: Process-local L1 cache with server-assisted Redis invalidation, soft-TTL background refresh, and opt-in single-flight point-read coalescing for hot-key stampedes.
- Composite Indexes & Keyset Pagination: Exact 64-bit
Long+ lexical composite indexes, cursor-based seek pagination, andCountFacetReadModelfor pre-aggregated dashboard counters. - Java 21 Virtual Threads, Async & Reactor: Carrier-pin-free virtual-thread execution,
AsyncEntityRepository(CompletableFuture), and optional Project Reactor (Mono/Flux) adapters viacachedb-reactor. - Spring Ecosystem Integration: Compile-time Spring Data (
Repository/CrudRepository/Page/Slice/ keysetWindow) viacachedb-spring-data, plus synchronous Spring@Cacheable/@CachePut/@CacheEvictsupport. - Multi-Tenant Governance & Data Protection:
@CacheTenantIdisolation, per-tenant quotas, AES-GCM field encryption (@CacheEncrypted),@CacheRetentionsweepers, and entity-scoped tenant purge. - Operations Console, Migration Planner & Observability: Built-in
/cachedb-admindashboard (protect behind an internal gateway in production), side-by-side SQL-vs-CacheDB Migration Planner,cachedb:doctorMaven build verification, and Micrometer / OpenTelemetry instrumentation.
Explore a complete, ready-to-run Spring Boot REST API with Docker Compose, seed/warm jobs, projections, stock dashboards, and Postman collections:
| Sample Project | Database & Port | Highlights |
|---|---|---|
| PostgreSQL Sample | PostgreSQL 16 (:8091) |
Full e-commerce & operations API, projections, catalog snapshots, Spring Data, Spring Cache, async/Reactor, Postman collections |
| SQL Server Sample | SQL Server 2022 (:8092) |
Identical domain & REST API contract tuned for SQL Server lock/isolation settings |
| Oracle Sample | Oracle Database 23ai (:8093) |
Identical domain & REST API contract tuned for Oracle sequences, timeouts, and JDBC |
| Operations & Load Demo | PostgreSQL + Load UI (:8090) |
Interactive traffic generator (LOW / MEDIUM / HIGH), live /cachedb-admin console, and Migration Planner walkthrough |
- Start any provider sample above with
docker compose up -dandSPRING_PROFILES_ACTIVE=demo mvn spring-boot:run. - Trigger
POST /api/demo/seedto populate sample customers, products, and orders. - Call
GET /api/orders/archive?customerId=1&limit=10to see the bounded SQL archive route. - Trigger
POST /api/warm/orders/customer/1?limit=100&projectionOnly=trueto warm the Redis timeline projection. - Call
GET /api/customers/1/orders?limit=10to read the hot Redis cursor page, then open/cachedb-adminto inspect live metrics and routes.
Full index: Documentation Map
| Topic | Guide |
|---|---|
| Getting Started & Fit | Getting Started · Concepts & Assumptions · ORM Alternative Guide · Architecture |
| Repositories & Read Models | Declarative Repositories · Snapshot Projections · Scheduled Warm · Use Case Examples |
| Performance & Indexing | Near Cache, Facets & Indexes · Composite Range Indexes · COUNT/FACET Read Models · Redis Read Coalescing |
| Spring, Async & Security | Spring Boot Starter · Spring Data · Spring Cache · Async & Reactor · Tenant Data Protection |
| Migration & Operations | Migration Planner · Production Tuning Guide · Tuning Parameters · Production Certification · Observability & Tracing |
| Providers & Releases | Database Provider SPI · Oracle Provider · Upgrading to 0.19 · v0.19.4 Release Notes · Release History |
- Changelog · Downloads & Releases
- Contributing · Code of Conduct
- Security Policy · Support
- Licensed under the MIT License.