Class DbCache<T extends DbObject>
java.lang.Object
ghidra.program.database.DbCache<T>
- Type Parameters:
T- the type of the database object
- Direct Known Subclasses:
CodeUnitCache
A DbObject cache that efficiently manages the use of the database lock and uses a
factory to create objects in the cache when they are not present.
This version of the cache is designed to be used without first acquiring a database lock. It will first attempt to retrieve the object without acquiring the lock. If that fails, it will acquire the lock, attempt to refresh the object if necessary or possibly create a new instance using the factory and add it to the cache.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the given database object to the cache.voiddelete(long key) Removes the object with the given key from the cache.voidDelete all objects from HashMap whose key is contained within the specified keyRanges.getCachedInstance(DBRecord dbRecord) Retrieves the database object with the given record and associated key from the cache.getCachedInstance(Long key) Retrieves the database object with the given key from the cache.Returns an List of all the cached objects.getIfValid(Long key) Retrieves the object from the cache, but only if it already exists and is valid in the cache.intGet the current cache modification counter value which corresponds to the number of times the entire cache has been invalidated.Retrieves the object with the given key from the cache with checking if it is valid or needs to be refreshed.voidMarks all the cached objects as invalid.voidkeyChanged(long oldKey, long newKey) Updates the cache for an object whose key has changed.intsize()Returns the number of objects currently in the cache.
-
Field Details
-
DUMMY
-
INVALID_COUNT
public static final int INVALID_COUNT- See Also:
-
lock
-
factory
-
refCache
-
-
Constructor Details
-
DbCache
-
-
Method Details
-
size
public int size()Returns the number of objects currently in the cache. A database lock is not required.- Returns:
- the number of objects currently in the cache.
-
add
-
getCachedInstance
Retrieves the database object with the given key from the cache. This differs from the super's get() method in that it does not require that the database lock be acquired prior to calling this method and in fact performs better if the lock is not acquired. This version will first look in the cache and if it finds one that is definitely valid (there is a quick check that doesn't require the lock), it returns it immediately. Otherwise, the cache doesn't have the object or the object needs refreshing. In this case, this method will acquire the lock, attempt refresh the object if it exists, and if necessary call a factory method to create a new instance and add it to the cache.- Parameters:
key- the key of the object to retrieve.- Returns:
- the cached object or null if the object with that key is not currently cached.
-
getIfValid
Retrieves the object from the cache, but only if it already exists and is valid in the cache. It will not attempt to refresh the object or call the factory method to create new instances.- Parameters:
key- the key of the object to retrieve.- Returns:
- the cached object or null if the object with that key is not currently cached and valid.
-
getRaw
Retrieves the object with the given key from the cache with checking if it is valid or needs to be refreshed. It will not use the factory to create new instances if they don't exist. This method is used in very specialized situations where the caller has already done checking and they know the status of the object and how to refresh it cheaply if needed.- Parameters:
key- the key of the object to retrieve- Returns:
- the object directly from the cache if one exists in the cache.
-
getCachedInstance
Retrieves the database object with the given record and associated key from the cache. This form should be used in conjunction with record iterators to avoid unnecessary record query during a possible object refresh. To benefit from the record the cached object must implement theDbObject.refresh(DBRecord)method which by default ignores the record and simply callsDbObject.refresh(DBRecord).This method is similar to the get() method in that it can be called without the database lock. It will first check if the object is in the cache and definitely valid before acquiring the lock and refreshing or creating the database object.
- Parameters:
dbRecord- the valid record corresponding to the object to be retrieved and possibly used to refresh the associated object if found in cache- Returns:
- the cached object or null if the object with that key is not currently cached.
-
getCachedObjects
-
delete
-
invalidate
public void invalidate()Marks all the cached objects as invalid. Invalid objects will have to refresh themselves before they are allowed to be used. If an invalidated object cannot refresh itself, then the object is removed from the cache and discarded and the application can no longer use that instance of the object. -
delete
public void delete(long key) Removes the object with the given key from the cache. A database lock is not required.- Parameters:
key- the key of the object to remove.
-
keyChanged
public void keyChanged(long oldKey, long newKey) Updates the cache for an object whose key has changed.- Parameters:
oldKey- the old keynewKey- the new key
-
getModificationCount
public int getModificationCount()Get the current cache modification counter value which corresponds to the number of times the entire cache has been invalidated.- Returns:
- the current modification counter value
-