51Degrees Pipeline Java  4.1Newer Version 4.4

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.

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

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


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



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

◆ get()

V fiftyone.caching.LruCacheBase< K, V >.get ( K   key )

Retrieves the value for key requested.

key - or the item required
an instance of the value associated with the key or null

Implements fiftyone.caching.Cache< K, V >.

◆ getCacheMisses()

long fiftyone.caching.LruCacheBase< K, V >.getCacheMisses ( )
number of cache misses.

◆ getCacheRequests()

long fiftyone.caching.LruCacheBase< K, V >.getCacheRequests ( )
number of requests received by the cache.

◆ getCacheSize()

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

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

capacity of the cache.

◆ getPercentageMisses()

double fiftyone.caching.LruCacheBase< K, V >.getPercentageMisses ( )
the percentage of times cache request did not return a result.
On This Page