Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caching for token validation results #41

Closed

Conversation

devondragon
Copy link
Owner

Summary

  • Created TurnstileCacheProperties for configuring cache behavior with TTL, size limits
  • Implemented TurnstileCacheConfig with Caffeine cache provider support
  • Added @Cacheable annotations with smart key generation for improved performance
  • Implemented cache bypass methods with validateTurnstileResponseNoCache
  • Updated imports and configuration in main application class
  • Added appropriate test configuration and test cases
  • Updated dependencies to include Spring Cache and Caffeine
  • Added comprehensive JavaDoc documentation

Implementation Details

  • Cache configuration is fully customizable via application properties
  • Cache keys are generated using token and remoteIp parameters
  • Validation results are cached based on configurable TTL (default 300s)
  • Maximum cache size is configurable (default 1000 entries)
  • Feature can be completely disabled via configuration
  • No-cache methods allow bypassing cache when needed

Test Plan

  • Added CachingTest to verify caching functionality works correctly
  • Verified that same token returns cached result on subsequent calls
  • Confirmed that bypass methods work correctly
  • All tests pass with both JDK 17 and 21

Fixes #32

- Created TurnstileCacheProperties for configuring cache behavior with TTL, size limits
- Implemented TurnstileCacheConfig with Caffeine cache provider support
- Added @Cacheable annotations with smart key generation for improved performance
- Implemented cache bypass methods with validateTurnstileResponseNoCache
- Updated imports and configuration in main application class
- Added appropriate test configuration and test cases
- Updated dependencies to include Spring Cache and Caffeine
- Added comprehensive JavaDoc documentation

This implementation significantly reduces API calls to Cloudflare by caching
validation results, while still allowing explicit cache bypassing when needed.

Fixes #32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add caching for token validation results
1 participant