Skip to content

About the use of CacheWriter after it has been removed #686

Answered by ben-manes
WeiMingzhi asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @WeiMingzhi,

Cache<String, Integer> cache = Caffeine.newBuilder().build();
cache.asMap().compute("a", (key, oldValue) -> {
  int newValue = 1;
  System.out.printf("%s: %d => %d%n", key, oldValue, newValue);
  return newValue;
});
cache.asMap().compute("a", (key, oldValue) -> {
  int newValue = 2;
  System.out.printf("%s: %d => %d%n", key, oldValue, newValue);
  return newValue;
});
System.out.printf("Cache contains: %s%n", cache.asMap());

cache.asMap().compute("a", (key, oldValue) -> {
  System.out.printf("%s: %d => %d%n", key, oldValue, null);
  return null;
});
System.out.printf("Cache contains: %s%n", cache.asMap());
a: null => 1
a: 1 => 2
Cache contains: {a=2}
a: 2 => null
Cache c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@WeiMingzhi
Comment options

Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants