0

What is the main difference between jcache-component, ehcache-component and caffeine-cache-component (or any other); and which one would be the most appropriate for a simple use case in Apache Camel?


The problem:

I need to read a relatively large CSV file, split it and insert each row somewhere via a REST service. The service requires an authentication token that expires in a few minutes, so it is possible to insert multiple records with the same token, but not all.

Therefore, I want to cache the authentication token (a simple string) to reuse it (say for 100 records, or maybe 1 minute) and then get a new token. Note that since the split creates a new exchange for each iteration, you cannot use headers or properties to share information (the authentication token) between iterations.

from("timer://runOnce?repeatCount=1")
    .to("direct:read-csv-data")
    .split(body())
        .to("direct:set-authorization")
        .to("direct:insert-data-rest")
    .end();

from("direct:set-authorization")
    .choice()
        .when(this::requiresAuthorizationRenewal).to("direct:get-authorization-and-save-in-cache")
        .otherwise().to("direct:get-authorization-from-cache")
    .end();

(The requiresAuthorizationRenewal predicate uses the CamelSplitIndex exchange property to determine when to renew the token, e.g., every 100 records)

lcnicolau
  • 3,252
  • 4
  • 36
  • 53

0 Answers0