This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new b94544b  fix errors and improve caffeine example
b94544b is described below

commit b94544b02e190205153bddc8cc9dea9cb8038bdb
Author: Kuthumi Pepple <[email protected]>
AuthorDate: Fri Jun 24 14:25:21 2022 +0100

    fix errors and improve caffeine example
---
 generic-examples/caffeine/README.md             | 34 ++++++++++++++++++++++++-
 generic-examples/caffeine/camel-caffeine.groovy | 10 ++++----
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/generic-examples/caffeine/README.md 
b/generic-examples/caffeine/README.md
index 0be603f..b10058a 100644
--- a/generic-examples/caffeine/README.md
+++ b/generic-examples/caffeine/README.md
@@ -1,3 +1,35 @@
 # Caffeine Camel K examples
 
-Find useful examples about how to use Caffeine in a Camel K integration.
\ No newline at end of file
+This examples demonstrate how to use Caffeine cache in a Camel K integration.
+
+You can find more information about Apache Camel and Apache Camel K on the 
[official Camel website](https://camel.apache.org).
+
+## Before you begin
+
+Read the general instructions in the [root README.md file](/README.md) for 
setting up your environment and the Kubernetes cluster before looking at this 
example.
+
+Make sure you've read the [installation 
instructions](https://camel.apache.org/camel-k/latest/installation/installation.html)
 for your specific
+cluster before starting the example.
+
+## Understanding the Example
+
+- [`CaffeineCacheSample.java`](./CaffeineCacheSample.java) defines a route 
that every second:
+    - uses message headers to PUT a key-value pair in the cache and log the 
result
+    - uses message headers to GET the cached value for the key and log the 
result
+    - uses message headers to INVALIDATE the cached value for the key, logs 
about invalidating the data
+    - uses message headers to GET the now discarded cached value for the key 
and log the result
+- [`camel-caffeine.groovy`](./camel-caffeine.groovy) does the same thing as 
`CaffeineCacheSample.java` except that a bean is defined and accumulation of 
cache statistics is enabled.
+
+## Running the Example
+To see the logs in the terminal, run the integration in dev mode:
+```
+kamel run --dev CaffeineCacheSample.java
+```
+
+The following should be logged continuously to the terminal:
+```console
+[1] 2022-06-24 12:58:06,352 INFO  [route1] (Camel (camel-1) thread #1 - 
timer://tick) Result of Action PUT with key 1 is: Hello
+[1] 2022-06-24 12:58:06,355 INFO  [route1] (Camel (camel-1) thread #1 - 
timer://tick) Result of Action GET with key 1 is: Hello
+[1] 2022-06-24 12:58:06,355 INFO  [route1] (Camel (camel-1) thread #1 - 
timer://tick) Invalidating entry with key 1
+[1] 2022-06-24 12:58:06,357 INFO  [route1] (Camel (camel-1) thread #1 - 
timer://tick) The Action GET with key 1 has result? false
+```
\ No newline at end of file
diff --git a/generic-examples/caffeine/camel-caffeine.groovy 
b/generic-examples/caffeine/camel-caffeine.groovy
index fb09740..0987bfe 100644
--- a/generic-examples/caffeine/camel-caffeine.groovy
+++ b/generic-examples/caffeine/camel-caffeine.groovy
@@ -19,7 +19,7 @@
 //
 // To run this integration use:
 //
-//     kamel run groovy examples/camel-caffeine.groovy
+//     kamel run camel-caffeine.groovy
 //
 
 import com.github.benmanes.caffeine.cache.Caffeine
@@ -34,26 +34,26 @@ from('timer:tick')
     it.in.headers['CamelCaffeineAction'] = 'PUT'
     it.in.headers['CamelCaffeineKey'] = 1
   }
-  .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+  .toF('caffeine-cache://%s', 'caffeineCache')
   .log('Result of Action ${header.CamelCaffeineAction} with key 
${header.CamelCaffeineKey} is: ${body}')
   .setBody().constant(null)
   .process {
     it.in.headers['CamelCaffeineAction'] = 'GET'
     it.in.headers['CamelCaffeineKey'] = 1
   }
-  .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+  .toF('caffeine-cache://%s', 'caffeineCache')
   .log('Result of Action ${header.CamelCaffeineAction} with key 
${header.CamelCaffeineKey} is: ${body}')
   .setBody().constant(null)
   .process {
     it.in.headers['CamelCaffeineAction'] = 'INVALIDATE'
     it.in.headers['CamelCaffeineKey'] = 1
   }
-  .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+  .toF('caffeine-cache://%s', 'caffeineCache')
   .log('Invalidating entry with key ${header.CamelCaffeineKey}')
   .setBody().constant(null)
   .process {
     it.in.headers['CamelCaffeineAction'] = 'GET'
     it.in.headers['CamelCaffeineKey'] = 1
   }
-  .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+  .toF('caffeine-cache://%s', 'caffeineCache')
   .log('The Action ${header.CamelCaffeineAction} with key 
${header.CamelCaffeineKey} has result? ${header.CamelCaffeineActionHasResult}');

Reply via email to