private void addToCache(K key, V value) { addToCache(new CacheEntry<K, V>(key, value)); }
private void addToCache(K key, V value) { addToCache(new CacheEntry<K, V>(key, value)); }
private void addToCache(K key, V value) { addToCache(new CacheEntry<K, V>(key, value)); }
@SuppressWarnings("unchecked") // Safe because we only cast if key is found in map. @Override public V get(@Nullable Object key) { V value = getIfCached(key); if (value != null) { return value; } value = getWithoutCaching(key); if (value != null) { addToCache((K) key, value); } return value; }
@Override protected V getIfCached(@Nullable Object key) { V value = super.getIfCached(key); if (value != null) { return value; } // Store a local reference to the cache entry. If the backing map is immutable, this, // in combination with immutable cache entries, will ensure a thread-safe cache. CacheEntry<K, V> entry; // Check cache. We use == on purpose because it's cheaper and a cache miss is ok. entry = cacheEntry1; if (entry != null && entry.key == key) { return entry.value; } entry = cacheEntry2; if (entry != null && entry.key == key) { // Promote second cache entry to first so the access pattern // [K1, K2, K1, K3, K1, K4...] still hits the cache half the time. addToCache(entry); return entry.value; } return null; }
@SuppressWarnings("unchecked") // Safe because we only cast if key is found in map. @Override public V get(@NullableDecl Object key) { V value = getIfCached(key); if (value != null) { return value; } value = getWithoutCaching(key); if (value != null) { addToCache((K) key, value); } return value; }
@Override protected V getIfCached(@NullableDecl Object key) { V value = super.getIfCached(key); if (value != null) { return value; } // Store a local reference to the cache entry. If the backing map is immutable, this, // in combination with immutable cache entries, will ensure a thread-safe cache. CacheEntry<K, V> entry; // Check cache. We use == on purpose because it's cheaper and a cache miss is ok. entry = cacheEntry1; if (entry != null && entry.key == key) { return entry.value; } entry = cacheEntry2; if (entry != null && entry.key == key) { // Promote second cache entry to first so the access pattern // [K1, K2, K1, K3, K1, K4...] still hits the cache half the time. addToCache(entry); return entry.value; } return null; }
@SuppressWarnings("unchecked") // Safe because we only cast if key is found in map. @Override public V get(@NullableDecl Object key) { V value = getIfCached(key); if (value != null) { return value; } value = getWithoutCaching(key); if (value != null) { addToCache((K) key, value); } return value; }
@Override protected V getIfCached(@NullableDecl Object key) { V value = super.getIfCached(key); if (value != null) { return value; } // Store a local reference to the cache entry. If the backing map is immutable, this, // in combination with immutable cache entries, will ensure a thread-safe cache. CacheEntry<K, V> entry; // Check cache. We use == on purpose because it's cheaper and a cache miss is ok. entry = cacheEntry1; if (entry != null && entry.key == key) { return entry.value; } entry = cacheEntry2; if (entry != null && entry.key == key) { // Promote second cache entry to first so the access pattern // [K1, K2, K1, K3, K1, K4...] still hits the cache half the time. addToCache(entry); return entry.value; } return null; }
private void addToCache(K key, V value) { addToCache(new CacheEntry<K, V>(key, value)); }
private void addToCache(K key, V value) { addToCache(new CacheEntry<K, V>(key, value)); }
@Override protected V getIfCached(@NullableDecl Object key) { V value = super.getIfCached(key); if (value != null) { return value; } // Store a local reference to the cache entry. If the backing map is immutable, this, // in combination with immutable cache entries, will ensure a thread-safe cache. CacheEntry<K, V> entry; // Check cache. We use == on purpose because it's cheaper and a cache miss is ok. entry = cacheEntry1; if (entry != null && entry.key == key) { return entry.value; } entry = cacheEntry2; if (entry != null && entry.key == key) { // Promote second cache entry to first so the access pattern // [K1, K2, K1, K3, K1, K4...] still hits the cache half the time. addToCache(entry); return entry.value; } return null; }
@Override protected V getIfCached(@Nullable Object key) { V value = super.getIfCached(key); if (value != null) { return value; } // Store a local reference to the cache entry. If the backing map is immutable, this, // in combination with immutable cache entries, will ensure a thread-safe cache. CacheEntry<K, V> entry; // Check cache. We use == on purpose because it's cheaper and a cache miss is ok. entry = cacheEntry1; if (entry != null && entry.key == key) { return entry.value; } entry = cacheEntry2; if (entry != null && entry.key == key) { // Promote second cache entry to first so the access pattern // [K1, K2, K1, K3, K1, K4...] still hits the cache half the time. addToCache(entry); return entry.value; } return null; }
@SuppressWarnings("unchecked") // Safe because we only cast if key is found in map. @Override public V get(@NullableDecl Object key) { V value = getIfCached(key); if (value != null) { return value; } value = getWithoutCaching(key); if (value != null) { addToCache((K) key, value); } return value; }
@SuppressWarnings("unchecked") // Safe because we only cast if key is found in map. @Override public V get(@Nullable Object key) { V value = getIfCached(key); if (value != null) { return value; } value = getWithoutCaching(key); if (value != null) { addToCache((K) key, value); } return value; }