fiftyone.mobile.detection
Class Cache<K,V>

java.lang.Object
  extended by fiftyone.mobile.detection.Cache<K,V>

 class Cache<K,V>
extends Object

Used to speed the retrieval of detection results over duplicate requests.


Field Summary
private  ConcurrentHashMap<K,V> active
          The active cache.
private  ConcurrentHashMap<K,V> background
          The background cache.
private  long nextCacheService
          The next time the caches should be switched.
private  int serviceIntervalMS
          The time between cache services.
 
Constructor Summary
Cache(int serviceInterval)
          Constructs a new instance of the cache.
 
Method Summary
private  void service()
          Service the cache by switching the lists if the next service time has passed.
(package private)  void setActive(K key, V result)
           
(package private)  void setBackground(K key, V result)
           
(package private)  V tryGetValue(K key)
          Attempts to get the value with the given, or null if no key is found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextCacheService

private long nextCacheService
The next time the caches should be switched.


serviceIntervalMS

private int serviceIntervalMS
The time between cache services.


active

private ConcurrentHashMap<K,V> active
The active cache.


background

private ConcurrentHashMap<K,V> background
The background cache.

Constructor Detail

Cache

public Cache(int serviceInterval)
Constructs a new instance of the cache.

Parameters:
serviceInterval - number of seconds between switching the cache.
Method Detail

service

private void service()
Service the cache by switching the lists if the next service time has passed.


tryGetValue

V tryGetValue(K key)
Attempts to get the value with the given, or null if no key is found.


setActive

void setActive(K key,
               V result)

setBackground

void setBackground(K key,
                   V result)