Skip to content

Latest commit

 

History

History
91 lines (67 loc) · 2.48 KB

caffeine-cache-component.adoc

File metadata and controls

91 lines (67 loc) · 2.48 KB

Caffeine Cache

Since Camel 2.20

Only producer is supported

The Caffeine Cache component enables you to perform caching operations using the simple cache from Caffeine.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-caffeine</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
caffeine-cache://cacheName[?options]

You can append query options to the URI in the following format: ?option=value&option=#beanRef&…​.

Usage

Checking the operation result

Each time you’ll use an operation on the cache, you’ll have two different headers to check for status:

  • CaffeineConstants.ACTION_HAS_RESULT

  • CaffeineConstants.ACTION_SUCCEEDED

Examples

You can use your cache with the following code:

@BindToRegistry("cache")
Cache cache = Caffeine.newBuilder().recordStats().build();

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() {
            from("direct://start")
                .to("caffeine-cache://cache?action=PUT&key=1")
                .to("caffeine-cache://cache?key=1&action=GET")
                .log("Test! ${body}")
                .to("mock:result");
        }
    };
}

In this way, you’ll work always on the same cache in the registry.

spring-boot:partial$starter.adoc