Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko.util;
8 import android.support.v4.util.LruCache;
10 import java.util.concurrent.ConcurrentHashMap;
12 /**
13 * An LruCache that also supports a set of items that will never be evicted.
14 *
15 * Alas, LruCache is final, so we compose rather than inherit.
16 */
17 public class NonEvictingLruCache<K, V> {
18 private final ConcurrentHashMap<K, V> permanent = new ConcurrentHashMap<K, V>();
19 private final LruCache<K, V> evictable;
21 public NonEvictingLruCache(final int evictableSize) {
22 evictable = new LruCache<K, V>(evictableSize);
23 }
25 public V get(K key) {
26 V val = permanent.get(key);
27 if (val == null) {
28 return evictable.get(key);
29 }
30 return val;
31 }
33 public void putWithoutEviction(K key, V value) {
34 permanent.put(key, value);
35 }
37 public void put(K key, V value) {
38 evictable.put(key, value);
39 }
41 public void evictAll() {
42 evictable.evictAll();
43 }
44 }