michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.util; michael@0: michael@0: import android.support.v4.util.LruCache; michael@0: michael@0: import java.util.concurrent.ConcurrentHashMap; michael@0: michael@0: /** michael@0: * An LruCache that also supports a set of items that will never be evicted. michael@0: * michael@0: * Alas, LruCache is final, so we compose rather than inherit. michael@0: */ michael@0: public class NonEvictingLruCache { michael@0: private final ConcurrentHashMap permanent = new ConcurrentHashMap(); michael@0: private final LruCache evictable; michael@0: michael@0: public NonEvictingLruCache(final int evictableSize) { michael@0: evictable = new LruCache(evictableSize); michael@0: } michael@0: michael@0: public V get(K key) { michael@0: V val = permanent.get(key); michael@0: if (val == null) { michael@0: return evictable.get(key); michael@0: } michael@0: return val; michael@0: } michael@0: michael@0: public void putWithoutEviction(K key, V value) { michael@0: permanent.put(key, value); michael@0: } michael@0: michael@0: public void put(K key, V value) { michael@0: evictable.put(key, value); michael@0: } michael@0: michael@0: public void evictAll() { michael@0: evictable.evictAll(); michael@0: } michael@0: }