K - Key for the cache items.V - Value for the cache items.public class Cache<K,V> extends Object
The Least Recently Used (LRU) cache is used. LRU cache keeps track of what was used when in order to discard the least recently used items first. Every time a cache item is used the "age" of the item used is updated.
Cache is implemented using the doubly linked list of Nodes where each Node tracks the next and previous Node and contains a value. Cache entries are stored as a Key : Value pair.
For a vast majority of the real life environments a constant stream of unique User-Agents is a fairly rare event. Usually the same User-Agent can be encountered multiple times within a fairly short period of time as the user is making a subsequent request. Caching frequently occurring User-Agents improved detection speed considerably.
Some devices are also more popular than others and while the User-Agents for such devices may differ, the combination of components used would be very similar. Therefore internal caching is also used to take advantage of the more frequently occurring entities.
This class should not be called as it is part of the internal logic.
| Constructor and Description |
|---|
Cache(int cacheSize)
Constructs a new instance of the cache.
|
Cache(int cacheSize,
ICacheLoader<K,V> loader)
Constructs a new instance of the cache.
|
| Modifier and Type | Method and Description |
|---|---|
V |
get(K key)
Retrieves the value for key requested.
|
V |
get(K key,
ICacheLoader<K,V> loader)
Retrieves the value for key requested.
|
long |
getCacheMisses() |
long |
getCacheRequests() |
double |
getPercentageMisses() |
void |
resetCache()
Resets the 'stats' for the cache.
|
public Cache(int cacheSize)
cacheSize - The number of items to store in the cache.public Cache(int cacheSize,
ICacheLoader<K,V> loader)
cacheSize - The number of items to store in the cache.loader - used to fetch items not in the cache.public long getCacheMisses()
public long getCacheRequests()
public double getPercentageMisses()
public V get(K key) throws IOException
key - or the item required.IOException - if there was a problem accessing data file.public V get(K key, ICacheLoader<K,V> loader) throws IOException
key - or the item requiredloader - to fetch the items fromIOException - if there was a problem accessing data file.public void resetCache()
Copyright © 2015 51Degrees. All rights reserved.