Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is guava's Cache.invalidate(Object key) method not generic?

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?

like image 500
Matt Mills Avatar asked Feb 27 '12 03:02

Matt Mills


People also ask

Is Guava cache thread safe?

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.

How does Guava cache work?

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.

How does loading cache work?

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.


1 Answers

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.

like image 67
Louis Wasserman Avatar answered Nov 06 '22 07:11

Louis Wasserman