Croway commented on PR #2046:
URL: 
https://github.com/apache/camel-spring-boot/pull/2046#issuecomment-6287406954

   @ramu11 Thanks, the restructuring looks good. All unit tests and the Redis 
ITs pass locally. A few remaining points:
   
   **1. Docs: make it clear users can choose the backend.** The section only 
describes the Spring adapter. Please add something like:
   
   > **Choosing a backend**
   >
   > - **Spring Cache** (`camel.state-store.spring-cache.enabled=true`): reuses 
the application's `CacheManager` and its `spring.cache.*` configuration. It is 
limited to Spring's `Cache` API: no per-entry TTL, no atomic compare-and-set, 
and `keys()`/`size()` only on `ConcurrentMap`-backed caches.
   > - **Camel `KeyValueRepository`** (`camel-redis`, `camel-caffeine`, 
`camel-jcache`, `camel-sql`, `camel-infinispan`, …): supports per-entry TTL, 
atomic `putIfAbsent`/`replace`/conditional `delete`, and `keys()`/`size()`. 
Define it as a bean and leave the Spring Cache property disabled; the 
state-store auto-discovers it, and so do Aggregate, Idempotent Consumer and the 
Cache EIP.
   > - **Both**: with the Spring Cache factory enabled, every store uses it 
unless the endpoint names a Camel repository with `backend=#myRepo`, e.g. 
`state-store:sessions?backend=#redisRepo`.
   
   **2. Test the mixed setup.** No new dependencies are needed 
(`ConcurrentMapCacheManager` + `MemoryKeyValueRepository`):
   
   ```java
   private final ApplicationContextRunner runner = new 
ApplicationContextRunner()
           
.withConfiguration(AutoConfigurations.of(CamelAutoConfiguration.class,
                   StateStoreComponentAutoConfiguration.class, 
SpringCacheStateStoreAutoConfiguration.class))
           .withUserConfiguration(StateStoreComponentConverter.class)
           .withBean(CacheManager.class, ConcurrentMapCacheManager::new)
           .withBean("camelRepo", MemoryKeyValueRepository.class, 
MemoryKeyValueRepository::new);
   
   @Test
   void springFactoryAndCamelRepositoryCoexist() {
       
runner.withPropertyValues("camel.state-store.spring-cache.enabled=true").run(ctx
 -> {
           ProducerTemplate pt = 
ctx.getBean(CamelContext.class).createProducerTemplate();
           pt.sendBodyAndHeader("state-store:orders?operation=put", "o1", 
StateStoreConstants.KEY, "1");
           
pt.sendBodyAndHeader("state-store:sessions?operation=put&backend=#camelRepo", 
"s1", StateStoreConstants.KEY, "1");
   
           
assertThat(ctx.getBean(CacheManager.class).getCache("orders").get("1").get()).isEqualTo("o1");
           assertThat(ctx.getBean("camelRepo", 
MemoryKeyValueRepository.class).get("1")).isEqualTo("s1");
           
assertThat(ctx.getBean(CacheManager.class).getCache("sessions").get("1")).isNull();
       });
   }
   
   @Test
   void camelRepositoryIsUsedWhenSpringCacheIsDisabled() {
       runner.run(ctx -> {
           ctx.getBean(CamelContext.class).createProducerTemplate()
                   .sendBodyAndHeader("state-store:orders?operation=put", "o1", 
StateStoreConstants.KEY, "1");
           assertThat(ctx.getBean("camelRepo", 
MemoryKeyValueRepository.class).get("1")).isEqualTo("o1");
       });
   }
   ```
   
   **3. Redis IT TTL.** `runner()` sets `spring.cache.redis.time-to-live=250ms` 
for every test. `stateStoreOperationsUseRedisCacheManager` and 
`explicitEipAdaptersRoundTripSerializableValues` make several Redis calls on 
the same key, so on a slow CI agent an entry can expire mid-test. Only 
`providerLevelTimeToLiveExpiresEntries` needs a TTL, and it already sets `2s`. 
Please drop the shared one.
   
   **4. Nits.**
   - Import `DefaultExchangeHolder` in `SpringCacheStateStoreRedisIT` instead 
of using its fully qualified name.
   - `KeyValueRepository.class` in `@ConditionalOnClass` is redundant, since it 
is always on the classpath.
   


-- 
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]

Reply via email to