51Degrees Pipeline Java  4.1

51Degrees Pipeline for Java

fiftyone.caching.LruCacheBase< K, V > Class Template Reference abstract

Detailed Description

Many of the entities used by the detector are requested repeatably.

The cache improves memory usage and reduces strain on the garbage collector by storing previously requested entities for a short period of time to avoid the need to re-fetch them from the underlying storage mechanism.

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.

This implementation supports concurrency by using multiple linked lists in place of a single linked list in the original implementation. The linked list to use is assigned at random and stored in the cached item. This will generate an even set of results across the different linked lists. The approach reduces the probability of the same linked list being locked when used in a environments with a high degree of concurrency. If the feature is not required then the constructor should be provided with a concurrency value of 1.

Use for User-Agent caching. 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.

Parameters
<K> - key for the cache items
<V> - value for the cache items

Inheritance diagram for fiftyone.caching.LruCacheBase< K, V >:

[legend]

Collaboration diagram for fiftyone.caching.LruCacheBase< K, V >:

[legend]

Classes

class  CachedItem
An item stored in the cache along with references to the next and previous items.
class  CacheLinkedList
A linked list used in the LruCache implementation.

Public Member Functions

long  getCacheSize ()
The number of items the cache lists should have capacity for. More...
long  getCacheMisses ()
long  getCacheRequests ()
double  getPercentageMisses ()
V  get (K key)
Retrieves the value for key requested. More...
void  resetCache ()
Resets the 'stats' for the cache.
void  finalize ()
void  close ()

Protected Member Functions

CachedItem  add (K key, V value)
void  close (boolean closing)

Member Function Documentation

◆ getCacheSize()

long fiftyone.caching.LruCacheBase< K, V >.getCacheSize ( )

The number of items the cache lists should have capacity for.

Returns
capacity of the cache.