From the javadocs:
public interface Cache<K,V> extends Function<K,V> {
//...
void invalidate(Object key);
//...
}
Why is this not rendered as a generic method:
void invalidate(K key);
Is there a technical reason, a historical reason, or some other reason?
Cache entries are manually added using get(Object, Callable) or put(Object, Object) , and are stored in the cache until either evicted or manually invalidated. Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads.
Guava provides a very powerful memory based caching mechanism by an interface LoadingCache<K,V>. Values are automatically loaded in the cache and it provides many utility methods useful for caching needs.
Google offers a "loading cache", which is described as following: A semi-persistent mapping from keys to values. Values are automatically loaded by the cache, and are stored in the cache until either evicted or manually invalidated.
For the same reason that Map.remove
takes an Object argument, which is explained here and here.
This reason is neither technical nor historical: it's just...an objectively sensible reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With