oscerd commented on code in PR #19662:
URL: https://github.com/apache/camel/pull/19662#discussion_r2450856723


##########
components/camel-keycloak/src/main/docs/keycloak-component.adoc:
##########
@@ -3021,6 +3021,238 @@ policy.setIntrospectionCacheTtl(30); // 30 seconds
 
 NOTE: When a token is introspected and cached, subsequent requests with the 
same token will use the cached result until the TTL expires. Balance security 
requirements with performance needs.
 
+==== Pluggable Cache Implementation
+
+The token introspection feature supports pluggable cache implementations for 
flexible caching strategies. This allows you to choose the best caching 
solution for your performance and scalability requirements.
+
+===== Available Cache Types
+
+The component provides three cache implementations:
+
+1. **ConcurrentMap Cache** (default) - Simple in-memory cache using 
`ConcurrentHashMap`
+   - Time-based expiration (TTL)
+   - No external dependencies
+   - Suitable for basic use cases and backward compatibility
+
+2. **Caffeine Cache** (recommended for production) - High-performance cache 
with advanced features
+   - Time-based expiration
+   - Size-based eviction
+   - Detailed statistics (hit rate, miss rate, evictions)
+   - Optimized for high throughput
+   - Requires `caffeine` dependency (marked as optional)
+
+3. **No Cache** - Disables caching completely
+   - Every token is introspected on each request
+   - Useful for testing or strict security requirements
+
+===== Using Caffeine Cache
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+import org.apache.camel.component.keycloak.security.cache.TokenCacheType;
+
+// Create introspector with Caffeine cache for high performance
+KeycloakTokenIntrospector introspector = new KeycloakTokenIntrospector(
+    serverUrl,
+    realm,
+    clientId,
+    clientSecret,
+    TokenCacheType.CAFFEINE,
+    300,         // TTL in seconds (5 minutes)
+    10000,       // max cache size (0 for unlimited)
+    true         // record statistics
+);
+
+// Check cache statistics
+TokenCache.CacheStats stats = introspector.getCacheStats();
+if (stats != null) {
+    System.out.println("Cache hit rate: " + stats.getHitRate());
+    System.out.println("Total hits: " + stats.getHitCount());
+    System.out.println("Total misses: " + stats.getMissCount());
+    System.out.println("Evictions: " + stats.getEvictionCount());
+}
+
+// Get current cache size
+long size = introspector.getCacheSize();
+System.out.println("Cached tokens: " + size);
+----
+====
+
+===== Custom Cache Configuration
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+import org.apache.camel.component.keycloak.security.cache.TokenCache;
+import org.apache.camel.component.keycloak.security.cache.CaffeineTokenCache;
+
+// Create a custom cache with specific settings
+TokenCache customCache = new CaffeineTokenCache(
+    600,         // 10 minutes TTL
+    50000,       // max 50k entries
+    true         // enable stats
+);
+
+// Use the custom cache instance
+KeycloakTokenIntrospector introspector = new KeycloakTokenIntrospector(
+    serverUrl,
+    realm,
+    clientId,
+    clientSecret,
+    customCache
+);
+----
+====
+
+===== Cache Configuration in Security Policy
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+// High-performance policy with Caffeine cache
+KeycloakSecurityPolicy highPerfPolicy = new KeycloakSecurityPolicy();
+highPerfPolicy.setServerUrl("http://localhost:8080";);
+highPerfPolicy.setRealm("production-realm");
+highPerfPolicy.setClientId("api-service");
+highPerfPolicy.setClientSecret("api-secret");
+highPerfPolicy.setRequiredRoles("user");
+
+// Enable introspection with Caffeine cache
+highPerfPolicy.setUseTokenIntrospection(true);
+highPerfPolicy.setIntrospectionCacheType(TokenCacheType.CAFFEINE);
+highPerfPolicy.setIntrospectionCacheTtl(120);  // 2 minutes
+highPerfPolicy.setIntrospectionCacheMaxSize(5000);  // max 5k tokens
+highPerfPolicy.setIntrospectionCacheStats(true);  // enable statistics
+
+from("rest:get:/api/data")
+    .policy(highPerfPolicy)
+    .to("bean:dataService?method=getData");
+----
+
+YAML::
++
+[source,yaml]
+----
+# Bean definition with Caffeine cache
+beans:
+  - name: highPerfPolicy
+    type: org.apache.camel.component.keycloak.security.KeycloakSecurityPolicy
+    properties:
+      serverUrl: "http://localhost:8080";
+      realm: "production-realm"
+      clientId: "api-service"
+      clientSecret: "api-secret"
+      requiredRoles: "user"
+      useTokenIntrospection: true
+      introspectionCacheType: "CAFFEINE"
+      introspectionCacheTtl: 120
+      introspectionCacheMaxSize: 5000
+      introspectionCacheStats: true
+----
+====
+
+===== Maven Dependency for Caffeine
+
+To use Caffeine cache, add the following dependency to your project:
+
+[source,xml]
+----
+<dependency>

Review Comment:
   it makes sense, let me modify this.



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