rzonta commented on issue #1984:
URL: https://github.com/apache/camel-k/issues/1984#issuecomment-819373197
@lancerdima you need to bind a instance of caffeine cache into Camel Registry
```
import org.apache.camel.BindToRegistry;
import org.apache.camel.builder.RouteBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class CacheTest extends RouteBuilder {
@BindToRegistry
public static Cache<String, Object> cache() {
return Caffeine.newBuilder()
.build();
}
@Override
public void configure() throws Exception {
from("timer:offsetHandler?fixedRate=true&period=10000&delay=5000")
.to("caffeine-cache:cache?key=offset&action=GET")
.log("Old value: ${body}")
.setBody(simple("${headers.CamelTimerCounter}"))
.to("caffeine-cache:cache?action=PUT&key=offset")
.log("New value: ${body}");
}
}
```
Then the result will be what you expect:
```
[1] 2021-04-14 09:23:00,326 INFO [route1] (Camel (camel-1) thread #0 -
timer://offsetHandler) Old value:
[1] 2021-04-14 09:23:00,330 INFO [route1] (Camel (camel-1) thread #0 -
timer://offsetHandler) New value: 1
[1] 2021-04-14 09:23:10,300 INFO [route1] (Camel (camel-1) thread #0 -
timer://offsetHandler) Old value: 1
[1] 2021-04-14 09:23:10,301 INFO [route1] (Camel (camel-1) thread #0 -
timer://offsetHandler) New value: 2
[1] 2021-04-14 09:23:20,299 INFO [route1] (Camel (camel-1) thread #0 -
timer://offsetHandler) Old value: 2
[1] 2021-04-14 09:23:20,300 INFO [route1] (Camel (camel-1) thread #0 -
timer://offsetHandler) New value: 3
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]