public class WeakLevel2Cache extends Object implements Level2Cache
Operates with 2 maps internally. One stores all pinned objects that have been selected to be retained by user's application. The other stores all other objects. This second map is the default location where objects are placed when being added here. The second (unpinned) map stores weak references meaning that they can get garbage collected as necessary by the JVM.
Maintains collections of the classes and the identities that are to be pinned if they ever are put into the cache. These are defined by the pinAll(), pin() methods.
All mutating methods, and the get method have been synchronized to prevent conflicts.
Level2Cache.PinnedClass| Modifier and Type | Field and Description |
|---|---|
protected ApiAdapter |
apiAdapter |
protected Map |
pinnedCache
Pinned objects cache.
|
protected Collection<Level2Cache.PinnedClass> |
pinnedClasses
Collection of pinned classes whose objects should be pinned if they ever reach the cache.
|
protected Collection |
pinnedIds
Collection of ids whose objects should be pinned if they ever reach the cache.
|
protected Map |
unpinnedCache
Unpinned objects cache.
|
| Modifier | Constructor and Description |
|---|---|
protected |
WeakLevel2Cache() |
|
WeakLevel2Cache(NucleusContext nucleusCtx)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Method to close the cache when no longer needed.
|
boolean |
containsOid(Object oid)
Method to check if an object with the specified id is in the cache
|
void |
evict(Object oid)
Method to evict an object from the cache.
|
void |
evictAll()
Method to evict all objects from the L2 cache.
|
void |
evictAll(Class pcClass,
boolean subclasses)
Method to evict all objects of the given types from the cache.
|
void |
evictAll(Collection oids)
Method to evict the objects with the specified ids.
|
void |
evictAll(Object[] oids)
Method to evict the objects with the specified ids.
|
CachedPC |
get(Object oid)
Accessor for an object from the cache.
|
Map<Object,CachedPC> |
getAll(Collection oids)
Accessor for a collection of objects from the cache.
|
int |
getNumberOfPinnedObjects()
Accessor for the number of pinned objects in the cache.
|
int |
getNumberOfUnpinnedObjects()
Accessor for the number of unpinned objects in the cache.
|
int |
getSize()
Accessor for the total number of objects in the L2 cache.
|
boolean |
isEmpty()
Accessor for whether the cache is empty.
|
void |
pin(Object oid)
Method to pin an object to the cache.
|
void |
pinAll(Class cls,
boolean subs)
Method to pin all objects of the given types.
|
void |
pinAll(Collection oids)
Method to pin all of the supplied objects
|
void |
pinAll(Object[] oids)
Method to pin all of the supplied objects
|
CachedPC |
put(Object oid,
CachedPC pc)
Method to put an object in the cache.
|
void |
putAll(Map<Object,CachedPC> objs)
Method to put several objects into the cache.
|
void |
unpin(Object oid)
Method to unpin an object
|
void |
unpinAll(Class cls,
boolean subs)
Method to unpin all objects of the specified types.
|
void |
unpinAll(Collection oids)
Method to unpin all of the supplied objects
|
void |
unpinAll(Object[] oids)
Method to unpin all of the specified objects
|
protected Collection<Level2Cache.PinnedClass> pinnedClasses
protected Collection pinnedIds
protected Map pinnedCache
protected transient Map unpinnedCache
protected ApiAdapter apiAdapter
protected WeakLevel2Cache()
public WeakLevel2Cache(NucleusContext nucleusCtx)
nucleusCtx - Contextpublic void close()
close in interface Level2Cachepublic void evict(Object oid)
evict in interface Level2Cacheoid - The id of the object to evictpublic void evictAll()
evictAll in interface Level2Cachepublic void evictAll(Class pcClass, boolean subclasses)
evictAll in interface Level2CachepcClass - The class to evictsubclasses - Whether to also evict subclassespublic void evictAll(Collection oids)
evictAll in interface Level2Cacheoids - The ids of the objects to evictpublic void evictAll(Object[] oids)
evictAll in interface Level2Cacheoids - The ids of the objects to evictpublic void pin(Object oid)
pin in interface Level2Cacheoid - The id of the object to pinpublic void pinAll(Class cls, boolean subs)
pinAll in interface Level2Cachecls - The classsubs - Whether to include subclassespublic void pinAll(Collection oids)
pinAll in interface Level2Cacheoids - The Object ids to pinpublic void pinAll(Object[] oids)
pinAll in interface Level2Cacheoids - The object ids to pinpublic void unpin(Object oid)
unpin in interface Level2Cacheoid - The object idpublic void unpinAll(Class cls, boolean subs)
unpinAll in interface Level2Cachecls - Base classsubs - Whether to include subclassespublic void unpinAll(Collection oids)
unpinAll in interface Level2Cacheoids - The object ids to unpinpublic void unpinAll(Object[] oids)
unpinAll in interface Level2Cacheoids - The object ids to unpinpublic CachedPC get(Object oid)
get in interface Level2Cacheoid - The Object IDpublic Map<Object,CachedPC> getAll(Collection oids)
Level2CachegetAll in interface Level2Cacheoids - The Object IDspublic int getNumberOfPinnedObjects()
getNumberOfPinnedObjects in interface Level2Cachepublic int getNumberOfUnpinnedObjects()
getNumberOfUnpinnedObjects in interface Level2Cachepublic int getSize()
getSize in interface Level2Cachepublic void putAll(Map<Object,CachedPC> objs)
Level2CacheputAll in interface Level2Cacheobjs - Map of cacheable object keyed by its oid.public CachedPC put(Object oid, CachedPC pc)
put in interface Level2Cacheoid - The Object id for this objectpc - The cacheable objectpublic boolean containsOid(Object oid)
containsOid in interface Level2Cacheoid - The object IDpublic boolean isEmpty()
isEmpty in interface Level2CacheCopyright © 2017. All rights reserved.