gnodet opened a new pull request, #25731:
URL: https://github.com/apache/camel/pull/25731
## Summary
_Claude Code on behalf of gnodet_
Introduces a block-scoped **Cache EIP** that provides transparent
read-through caching of route segments, backed by the `KeyValueRepository` SPI
from CAMEL-24463 (#25631).
> **Depends on:** #25631 (CAMEL-24463: KeyValueRepository SPI) — must be
merged first.
## Cache EIP vs Cache Components
Camel includes several cache **components** (`camel-caffeine`,
`camel-ehcache`, `camel-jcache`, `camel-infinispan`, etc.) that provide
endpoint-level cache operations (explicit GET/PUT/INVALIDATE). Those are useful
for fine-grained cache management (bulk ops, invalidation, event listening).
The Cache **EIP** covers the most common use case — _"cache the result of
this expensive block by key with a TTL"_ — without manual plumbing. It is
analogous to `@Cacheable` in Spring:
```java
// Without Cache EIP: 7+ lines of plumbing, tied to one cache technology
from("direct:start")
.setHeader("CamelCaffeineAction", constant("GET"))
.setHeader("CamelCaffeineKey", header("productId"))
.to("caffeine-cache:products")
.choice()
.when(body().isNull())
.to("http://expensive-service")
.setHeader("CamelCaffeineAction", constant("PUT"))
.to("caffeine-cache:products")
.end();
// With Cache EIP: 2 lines, backend-agnostic
from("direct:start")
.cache(simple("${header.productId}"))
.to("http://expensive-service")
.end();
```
| Aspect | Cache Components | Cache EIP |
|---|---|---|
| Granularity | Endpoint-level GET/PUT/DELETE | Block-scoped read-through |
| Lines of code | 7+ per cache point | 2 (`.cache(key)` … `.end()`) |
| Backend coupling | Tied to specific component | Backend-agnostic via
`KeyValueRepository` |
| Use case | Fine-grained cache management | Transparent result caching |
## What's Included
### New Files
- **`CacheDefinition`** (`core/camel-core-model`) — Model class extending
`OutputExpressionNode` with options: `keyValueRepository`, `ttl`, `cacheNull`
- **`CacheProcessor`** (`core/camel-core-processor`) — Runtime processor
with read-through caching logic, graceful error handling (cache errors never
propagate)
- **`CacheReifier`** (`core/camel-core-reifier`) — Reifier with
auto-discovery: explicit bean → registry ref → auto-discover single KVR →
auto-create `MemoryKeyValueRepository`
- **`CacheProcessorTest`** (`core/camel-core`) — 7 unit tests covering
hit/miss, TTL expiry, null key bypass, failed exchange not cached, null body
handling, expression clause form
- **`CacheTest.groovy`** (`dsl/camel-yaml-dsl`) — 2 YAML DSL tests
- **`cache-eip.adoc`** — Full EIP documentation with Java/XML/YAML examples
### Modified Files
- **`ProcessorDefinition`** — Added `cache()` and `cache(Expression)` DSL
methods
- **`ProcessorReifier`** — Registered `CacheReifier` for `CacheDefinition`
- **`nav.adoc`** — Added Cache EIP to EIP navigation
- **`camel-4x-upgrade-guide-4_23.adoc`** — Added "New Cache EIP" section
- Generated files: catalog models, XML/YAML schemas, deserializers
## Key Design Decisions
1. **Reuses `KeyValueRepository` SPI** — No new cache-specific SPI. Uses the
same abstraction that backs IdempotentConsumer and Aggregator, providing a
unified key-value layer.
2. **Graceful degradation** — All cache errors (read/write) are caught and
logged, never propagated to the exchange. Failed exchanges are never cached.
3. **Block-scoped pattern** — Follows the same architectural pattern as
CircuitBreaker, Saga, and DoTry (extends `OutputExpressionNode`).
4. **Zero-config default** — Works out of the box with
`MemoryKeyValueRepository` auto-creation; no configuration required for simple
use cases.
## Test Plan
- [x] `CacheProcessorTest` — 7 tests (hit, miss, TTL, null key, failed
exchange, null body, expression clause)
- [x] `CacheTest.groovy` — 2 YAML DSL tests (basic cache, cache with options)
- [x] `mvn clean install -pl core/camel-core -DskipTests` — compilation
verified
- [x] Code formatting verified (`mvn formatter:format impsort:sort`)
- [ ] Full CI build (pending)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]