0

I am using Spring boot. Application uses JWT token(another micro service) for authentication. I have to implement caching of JWT token. I am using Caffeine Cache.

Problem: Now the problem is this token expiry time is always dynamic and i have to match token expiry time with Cache expiry time. i.e.

Cache expiry time <= Token expiry time

Question: Is there any way to achieve this using Spring Cache?

Can we set value of below property dynamically, depends on JWT token expiry time?

spring.cache.caffeine.spec=expireAfterWrite=600s
DKS
  • 306
  • 1
  • 2
  • 16
  • You would like to set this property based on other property from your properties file or change it dynamically during runtime for each JWT that you receive? I am not sure if latter is possbile. – Michał Krzywański Aug 10 '21 at 13:02
  • Caffeine has support for per-entry custom expiration or dynamically changing a fixed duration period. These fall outside of Spring Cache which targets the simplest use-cases. My understanding is that in advanced cases they recommend using the native APIs directly. – Ben Manes Aug 10 '21 at 16:58
  • @MichałKrzywański Yes, I actually want the latter one. :( – DKS Aug 10 '21 at 17:46

1 Answers1

0

You can use System.setProperty() to change the value of environment variable from code.