Package ghidra.util.datastruct
Class ObjectCache<T>
java.lang.Object
ghidra.util.datastruct.ObjectCache<T>
- Type Parameters:
- T- Object type held by cache
ObjectClass provides a fixed-size long-key-based object cache.
 Both a hard and weak cache are maintained, where the weak cache is only
 limited by available memory.  This cache mechanism is useful in ensuring that
 only a single object instance for a given key exists.
 The weak cache is keyed, while the hard cache simply maintains the presence of an object in the weak cache.
- 
Constructor SummaryConstructorsConstructorDescriptionObjectCache(int hardCacheSize) Construct a keyed-object cache of size hardCacheSize.
- 
Method SummaryModifier and TypeMethodDescriptioncomputeIfAbsent(long key, Function<Long, T> mappingFunction) Get the current cached object which corresponds to specifiedkeyif contained in cache, otherwise themappingFunctionwill be invoked to instantiate a new object where that object will be added to the cache and returned.booleancontains(long key) Determine if the keyed-object exists in the cache.get(long key) Get the object from cache which corresponds to the specified key.voidAdd an object to the cachevoidremove(long key) Remove the specified keyed object from both hard and weak caches.voidsetHardCacheSize(int size) Adjust the hard cache sizeintsize()Return the hard cache size
- 
Constructor Details- 
ObjectCachepublic ObjectCache(int hardCacheSize) Construct a keyed-object cache of size hardCacheSize.- Parameters:
- hardCacheSize- hard cache size.
 
 
- 
- 
Method Details- 
containspublic boolean contains(long key) Determine if the keyed-object exists in the cache.- Parameters:
- key- object key
- Returns:
- true if object is cached
 
- 
getGet the object from cache which corresponds to the specified key.- Parameters:
- key- object key
- Returns:
- cached object
 
- 
computeIfAbsentGet the current cached object which corresponds to specifiedkeyif contained in cache, otherwise themappingFunctionwill be invoked to instantiate a new object where that object will be added to the cache and returned. If themappingFunctionreturns null nothing will be added to the cache and null will be returned by this method.- Parameters:
- key- object key
- mappingFunction- function used to obtain a new object if not currently present in cache.
- Returns:
- cached object
 
- 
sizepublic int size()Return the hard cache size- Returns:
- the hard cache size
 
- 
setHardCacheSizepublic void setHardCacheSize(int size) Adjust the hard cache size- Parameters:
- size- new hard cache size
 
- 
putAdd an object to the cache- Parameters:
- key- object key
- obj- the object
 
- 
removepublic void remove(long key) Remove the specified keyed object from both hard and weak caches. An object should be removed from the cache when it becomes invalid.- Parameters:
- key- object key
 
 
-