forked from apache/camel-k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camel-caffeine.groovy
43 lines (40 loc) · 1.45 KB
/
camel-caffeine.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// To run this integrations use:
//
// kamel run --runtime groovy examples/camel-caffeine.groovy
//
import com.github.benmanes.caffeine.cache.Caffeine
context {
registry {
caffeineCache = Caffeine.newBuilder().recordStats().build()
}
}
from('timer:tick')
.setBody().constant('Hello')
.process {
it.in.headers['CamelCaffeineAction'] = 'PUT'
it.in.headers['CamelCaffeineKey'] = 1
}
.toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
.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')
.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')
.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')
.log('The Action ${header.CamelCaffeineAction} with key ${header.CamelCaffeineKey} has result? ${header.CamelCaffeineActionHasResult}');