public class LRUCache extends Object
LinkedHashMap
.
This cache has a fixed maximum number of elements (cacheSize
). If the cache is full and another entry is
added, the LRU (least recently used) entry is dropped.
This class is thread-safe. All methods of this class are synchronized.
Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
Multi-licensed: EPL / LGPL / GPL / AL / BSD.
Modified slightly to fit the use of a wayback file cache.
Constructor and Description |
---|
LRUCache()
Constructor, where the arguments for the primary constructor is read from settings.
|
LRUCache(File dir,
int cacheSize)
Creates a new LRU cache.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the cache.
|
File |
get(String key)
Retrieves an entry from the cache.
The retrieved entry becomes the MRU (most recently used) entry. |
File |
getCacheDir() |
static LRUCache |
getInstance() |
void |
put(String key,
File value)
Adds an entry to this cache.
|
int |
usedEntries()
Returns the number of used entries in the cache.
|
public LRUCache(File dir, int cacheSize)
dir
- The directory where the file is stored.cacheSize
- the maximum number of entries that will be kept in this cache.public LRUCache()
public static LRUCache getInstance()
public File get(String key)
key
- the key whose associated value is to be returned.public void put(String key, File value)
key
- the key with which the specified value is to be associated.value
- a value to be associated with the specified key.public void clear()
public int usedEntries()
public File getCacheDir()
Copyright © 2005–2018 The Royal Danish Library, the National Library of France and the Austrian National Library.. All rights reserved.