public class PacketCache extends LinkedHashMap<CacheKey,PacketWrapper>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
PacketCache(int capacityMegaBytes,
int capacityBytes,
double maxAge)
Creates a cache with a size given by
cachesizemegabytes*2^20+cachesizebytes
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
PacketWrapper |
get(CacheKey key) |
PacketWrapper |
get(CacheKey key,
long now) |
int |
getByteCapacity() |
int |
getCapacity() |
PacketWrapper |
put(CacheKey key,
PacketWrapper value)
Adds a PacketWrapper object to this cache,
unless the size is more than maxCacheItemPercentage of the total size
|
PacketWrapper |
put(CacheKey key,
PacketWrapper result,
long timestamp)
Adds a BasicPacket array to this cache,
unless the size is more than maxCacheItemPercentage of the total size
|
PacketWrapper |
remove(CacheKey key) |
protected boolean |
removeEldestEntry(Map.Entry<CacheKey,PacketWrapper> eldest)
Overrides LinkedHashMap.removeEldestEntry as suggested to implement LRU cache.
|
void |
setMaxCacheItemPercentage(int maxCapacityPercentage)
Sets the max size of a cached item compared to the total size
Cache requests for larger objects will be ignored
|
int |
totalPacketSize() |
containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
public PacketCache(int capacityMegaBytes, int capacityBytes, double maxAge)
capacityMegaBytes
- the cache size, measured in megabytescapacityBytes
- additional number of bytes to add to the cache sizemaxAge
- seconds a cache entry is valid, 0 or less are illegal argumentspublic void clear()
clear
in interface Map<CacheKey,PacketWrapper>
clear
in class LinkedHashMap<CacheKey,PacketWrapper>
public void setMaxCacheItemPercentage(int maxCapacityPercentage)
protected boolean removeEldestEntry(Map.Entry<CacheKey,PacketWrapper> eldest)
removeEldestEntry
in class LinkedHashMap<CacheKey,PacketWrapper>
public int getCapacity()
public int getByteCapacity()
public PacketWrapper put(CacheKey key, PacketWrapper value)
put
in interface Map<CacheKey,PacketWrapper>
put
in class HashMap<CacheKey,PacketWrapper>
public PacketWrapper put(CacheKey key, PacketWrapper result, long timestamp)
timestamp
- the timestamp for the first packet in the array,
unit millisecondspublic PacketWrapper get(CacheKey key)
public PacketWrapper get(CacheKey key, long now)
public PacketWrapper remove(CacheKey key)
public int totalPacketSize()
Copyright © 2018. All rights reserved.