0

I have a requirement to rebuild the cache which is already declared and configured based on a condition.

private static final Cache<String, List<String>> CACHE = CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES).build();

Here I have already created the cache for 30 minutes. now let's say the user has a configuration to override the expiration time. So I need to rebuild the cache based on the configuration time.

Also is there any way to get cache last access time?

5
  • What exactly do you mean by rebuild the cache? Start a new empty cache? Guava's Cache doesn't provide access to when it was last accessed or let you change the expiration time after the cache is built; you must create the cache with the correct expiration time the first time. It doesn't look like your cache should be a static final. Commented May 21, 2024 at 8:09
  • Rebuilding the cache means, cache should use the new configuration rather than the default 30 mins. @LouisWasserman Commented May 21, 2024 at 8:19
  • You can't do that. Commented May 21, 2024 at 8:30
  • fwiw, the successor library, Caffeine, allows you to adjust the configuration for enabled features at runtime. This also allows for inspecting other metadata, like expiration order. Commented May 22, 2024 at 6:56
  • Can we do like per key with expiring time and evict the key value based on the time? rather than the global expiry time. Commented May 22, 2024 at 9:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.