fiftyone.mobile.detection.entities.stream
Class Cache<T>
java.lang.Object
fiftyone.mobile.detection.entities.stream.Cache<T>
- All Implemented Interfaces:
- Disposable
public class Cache<T>
- extends Object
- implements Disposable
Many of the entities used by the detector data set are requested repeatedly.
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
cache works by maintaining two dictionaries of entities keyed on their offset
or index. The inactive list contains all items requested since the cache was
created or last serviced. The active list contains all the items currently in
the cache. The inactive list is always updated when an item is requested.
When the cache is serviced the active list is destroyed and the inactive list
becomes the active list. i.e. all the items that were requested since the
cache was last serviced are now in the cache. A new inactive list is created
to store all items being requested since the cache was last serviced.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
itemsActive
ConcurrentHashMap<Integer,T> itemsActive
itemsInactive
ConcurrentHashMap<Integer,T> itemsInactive
cacheServiceTimer
private final Timer cacheServiceTimer
requests
AtomicInteger requests
misses
AtomicInteger misses
entityFactory
final BaseEntityFactory<T> entityFactory
Cache
Cache(BaseEntityFactory<T> creator)
- Constructs a new instance of the cache.
- Parameters:
serviceCacheInternal - Time between cache services
addRecent
void addRecent(int index,
T item)
getPercentageMisses
double getPercentageMisses()
dispose
public void dispose()
- Specified by:
dispose in interface Disposable