Purpose: A fixed size LRU cache
Using a linked list as well as the map from the superclass a LRU cache is maintained. When a get is executed the LRU list is updated and when a new object is inserted the object at the start of the list is deleted (provided the maxSize has been reached).
Responsibilities:
| Modifier and Type | Field and Description |
|---|---|
| protected LinkedCacheKey | first
Provide handles on the linked list |
| protected LinkedCacheKey | last
Provide handles on the linked list |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public CacheKey | createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)
Overrides org. |
| protected void | ensureFixedSize()
Reduces the size of the receiver down to the maxSize removing objects from the start of the linked list. |
| public CacheKey | Returns: the LinkedCacheKey or null if none found for primaryKeyis the primary key for the object to search for. primaryKeys, boolean forMerge)Overrides org. Implements org. |
| protected LinkedCacheKey | Returns: the added LinkedCacheKeyInsert a new element into the linked list of LinkedCacheKeys. |
| protected CacheKey | putCacheKeyIfAbsent(CacheKey searchKey)
Overrides org. |
| public Object | Returns: the LinkedCacheKey to be removed.Overrides org. Implements org. |
| protected LinkedCacheKey | Returns: the removed LinkedCacheKey.Remove the LinkedCacheKey from the linked list. |
| public synchronized void | updateMaxSize(int maxSize)
Overrides org. Implements org. |
| first | back to summary |
|---|---|
| protected LinkedCacheKey first Provide handles on the linked list | |
| last | back to summary |
|---|---|
| protected LinkedCacheKey last Provide handles on the linked list | |
| CacheIdentityMap | back to summary |
|---|---|
| public CacheIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isolated) | |
| createCacheKey | back to summary |
|---|---|
| public CacheKey createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime) Overrides org. Doc from org. Create the correct type of CacheKey for this map.
| |
| ensureFixedSize | back to summary |
|---|---|
| protected void ensureFixedSize() Reduces the size of the receiver down to the maxSize removing objects from the start of the linked list. | |
| getCacheKey | back to summary |
|---|---|
| public CacheKey getCacheKey(Object primaryKeys, boolean forMerge) Overrides org. Implements org. Access the object within the table for the given primaryKey. Move the accessed key to the top of the order keys linked list to maintain LRU. | |
| insertLink | back to summary |
|---|---|
| protected LinkedCacheKey insertLink(LinkedCacheKey key) Insert a new element into the linked list of LinkedCacheKeys. New elements (Recently Used) are added at the end (last). Callers of this method must synchronize on the start of the list (this.first).
| |
| putCacheKeyIfAbsent | back to summary |
|---|---|
| protected CacheKey putCacheKeyIfAbsent(CacheKey searchKey) Overrides org. Also insert the link if the cacheKey is put.
| |
| remove | back to summary |
|---|---|
| public Object remove(CacheKey key) Overrides org. Implements org. Remove the LinkedCacheKey from the cache as well as from the linked list. | |
| removeLink | back to summary |
|---|---|
| protected LinkedCacheKey removeLink(LinkedCacheKey key) Remove the LinkedCacheKey from the linked list. Callers of this method must synchronize on the start of the list (this.first).
| |
| updateMaxSize | back to summary |
|---|---|
| public synchronized void updateMaxSize(int maxSize) Overrides org. Implements org. INTERNAL: This method will be used to update the max cache size, any objects exceeding the max cache size will be remove from the cache. Please note that this does not remove the object from the identityMap, except in the case of the CacheIdentityMap.
| |