2020-04-20

Spring Cache evictIfPresent() method

Spring Cache evictIfPresent() method


default boolean evictIfPresent(Object key)

Evict the mapping for this key from this cache if it is present, expecting the key to be immediately invisible for subsequent lookups.

The default implementation delegates to evict(Object), returning false for not-determined prior presence of the key. Cache providers and in particular cache decorators are encouraged to perform immediate eviction if possible (e.g. in case of generally deferred cache operations within a transaction) and to reliably determine prior presence of the given key.

Parameters:
key - the key whose mapping is to be removed from the cache.

Returns:
true if the cache was known to have a mapping for this key before, false if it did not (or if prior presence could not be determined).


Example:

Cache cache = ....////Cache object
cache.evictIfPresent(Object);



1 comment:

  1. Doesn't work... evictIfPresent() always return false...

    ReplyDelete