Package org.apache.openjpa.datacache
Interface DataCache
-
- All Known Implementing Classes:
AbstractDataCache,ConcurrentDataCache,DelegatingDataCache,PartitionedDataCache
public interface DataCache extends Closeable, Clearable
Interface that must be implemented by any level 2 cache used by OpenJPA. Most data caches will choose to implement theConfigurableinterface as well so that they will be given the system configuration just after construction. Implementations should take care not to return timed out data.- Author:
- Patrick Linskey, Abe White, Pinaki Poddar
- See Also:
AbstractDataCache,DataCachePCData.isTimedOut()
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringNAME_DEFAULTThe name of the default data cache:default
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddExpirationListener(ExpirationListener listen)Add a new expiration event listener to this cache.voidclear()Remove all data from this cache.voidclose()Free the resources used by this cache.voidcommit(java.util.Collection<DataCachePCData> additions, java.util.Collection<DataCachePCData> newUpdates, java.util.Collection<DataCachePCData> existingUpdates, java.util.Collection<java.lang.Object> deletes)Perform a batch update of the cache.booleancontains(java.lang.Object oid)Returnstrueif this cache contains data corresponding tooid; otherwise returnsfalse.java.util.BitSetcontainsAll(java.util.Collection<java.lang.Object> oids)Returns the indexes of the oids in this cache.DataCachePCDataget(java.lang.Object oid)Return the cached object for the given oid.java.util.Map<java.lang.Object,DataCachePCData>getAll(java.util.List<java.lang.Object> keys)Gets objects from the caches for a given list of keys.booleangetEvictOnBulkUpdate()Returns whether the the cache needs to be updated when bulk updates as executed.java.lang.StringgetName()Returns a string name that can be used by end-user-visible code to identify this cache.DataCachegetPartition(java.lang.String name, boolean create)Gets the named partition.java.util.Set<java.lang.String>getPartitionNames()Gets the name of the known partitions.CacheStatisticsgetStatistics()Returns number of read/write request and cache hit ratio data.voidinitialize(DataCacheManager manager)Initialize any resources associated with the givenDataCacheManager.booleanisPartitioned()Affirms if this cache maintains partitions.booleanpin(java.lang.Object oid)Pin the value stored underoidinto the cache.voidpinAll(java.lang.Class<?> cls, boolean subs)Pin all oids for the given type.java.util.BitSetpinAll(java.util.Collection<java.lang.Object> oids)Pin all oids to the cache.DataCachePCDataput(DataCachePCData value)Set the cached value for the given instance.DataCachePCDataremove(java.lang.Object oid)Remove the value stored under the given oid.voidremoveAll(java.lang.Class<?> cls, boolean subclasses)Evict all values of a specified type.java.util.BitSetremoveAll(java.util.Collection<java.lang.Object> oids)Remove the values stored under the given oids.booleanremoveExpirationListener(ExpirationListener listen)Remove an expiration event listener from this cache.voidsetName(java.lang.String name)Sets a string name to be used to identify this cache to end-user needs.booleanunpin(java.lang.Object oid)Unpin the value stored underoidfrom the cache.voidunpinAll(java.lang.Class<?> cls, boolean subs)Unpin all oids associaed with the given type from the cache.java.util.BitSetunpinAll(java.util.Collection<java.lang.Object> oids)Unpin all oids from the cache.voidupdate(DataCachePCData value)Update the cached value for the given instance.voidwriteLock()Obtain a write lock on the cache.voidwriteUnlock()Release the write lock on the cache.
-
-
-
Field Detail
-
NAME_DEFAULT
static final java.lang.String NAME_DEFAULT
The name of the default data cache:default- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
java.lang.String getName()
Returns a string name that can be used by end-user-visible code to identify this cache.- Since:
- 0.2.5.0
-
setName
void setName(java.lang.String name)
Sets a string name to be used to identify this cache to end-user needs.- Since:
- 0.2.5.0
-
initialize
void initialize(DataCacheManager manager)
Initialize any resources associated with the givenDataCacheManager.
-
commit
void commit(java.util.Collection<DataCachePCData> additions, java.util.Collection<DataCachePCData> newUpdates, java.util.Collection<DataCachePCData> existingUpdates, java.util.Collection<java.lang.Object> deletes)
Perform a batch update of the cache. Add allDataCachePCDataobjects inadditionsand innewUpdates, make the appropriate modifications to all DataCachePCDatas inexistingUpdates, and delete all OIDs indeletes. All changes made to cached data must be made via this method. It is this method that is responsible for performing any side-effects that should happen on meaningful cache changes. Implementations should bear in mind that thedeletescollection may contain oids that are also in theadditionsmap. This is possible because it is valid for a user to delete an object with a particular oid and then add that object in the same batch.- Parameters:
additions- A collection ofDataCachePCDataobjects. These represent data that have been newly created, and thus must be added to the cache.newUpdates- A collection ofDataCachePCDataobjects. These represent data that have been modified but were not originally in the cache, and thus must be added to the cache.existingUpdates- A collection ofDataCachePCDataobjects. These represent data that have been modified and were originally loaded from the cache. It is up to the cache implementation to decide if these values must be re-enlisted in the cache. Some caches may return live data fromget(java.lang.Object)invocations, in which case these values need not be re-enlisted.deletes- A collection of object IDs that have been deleted and must therefore be dropped from the cache.
-
contains
boolean contains(java.lang.Object oid)
Returnstrueif this cache contains data corresponding tooid; otherwise returnsfalse.
-
containsAll
java.util.BitSet containsAll(java.util.Collection<java.lang.Object> oids)
Returns the indexes of the oids in this cache.
-
get
DataCachePCData get(java.lang.Object oid)
Return the cached object for the given oid. Modifying the returned object may or may not change the cached value; theupdate(org.apache.openjpa.datacache.DataCachePCData)method should be used to re-cache any changed objects.- Returns:
- the object matching the given oid, or null if none
-
put
DataCachePCData put(DataCachePCData value)
Set the cached value for the given instance. This does not result in an update of other caches. Rather, it should only be used for loading clean data into the cache. Meaningful changes to the state of the cache should be made via thecommit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method.- Returns:
- The previously cached value, or
nullif the value was not previously cached. SeeMap.put(K, V)for more information.
-
update
void update(DataCachePCData value)
Update the cached value for the given instance. This does not result in an update of other caches. Rather, it should only be used for loading clean data into the cache. Meaningful changes to the state of the cache should be made via thecommit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method. A cache implementation may or may not return a live object fromget(java.lang.Object)invocations. If an object retrieved from aget(java.lang.Object)operation needs to be updated, this method can be invoked instead of invokingput(org.apache.openjpa.datacache.DataCachePCData). The DataCache implementation can then make optimizations based on how itsget(java.lang.Object)method works.
-
remove
DataCachePCData remove(java.lang.Object oid)
Remove the value stored under the given oid. This does not result in an update of other caches. Rather, it should only be used for removing data in the cache. Meaningful changes to the state of the cache should be made via thecommit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method.- Returns:
- The previously cached value, or
nullif the oid was not previously cached. SeeMap.remove(java.lang.Object)for more information.
-
removeAll
java.util.BitSet removeAll(java.util.Collection<java.lang.Object> oids)
Remove the values stored under the given oids.- Returns:
- the indexes of the removed oids
- See Also:
remove(java.lang.Object)
-
removeAll
void removeAll(java.lang.Class<?> cls, boolean subclasses)Evict all values of a specified type.
-
clear
void clear()
Remove all data from this cache. This does not result in an update of other caches. Rather, it should only be used for clearing the cache. Meaningful changes to the state of the cache should be made via thecommit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method.
-
pin
boolean pin(java.lang.Object oid)
Pin the value stored underoidinto the cache. This method guarantees thatoid's value will not be dropped by the caching algorithm. This method does not affect the behavior ofremove(java.lang.Object).- Returns:
trueifoid's value was pinned into the cache;falseif the oid is not in the cache.
-
pinAll
java.util.BitSet pinAll(java.util.Collection<java.lang.Object> oids)
Pin all oids to the cache.- Returns:
- the indexes of the pinned oids
- See Also:
pin(java.lang.Object)
-
pinAll
void pinAll(java.lang.Class<?> cls, boolean subs)Pin all oids for the given type.- Parameters:
subs- Whether to include subclasses.
-
unpin
boolean unpin(java.lang.Object oid)
Unpin the value stored underoidfrom the cache. This method reverses a previous invocation ofpin(java.lang.Object). This method does not remove anything from the cache; it merely makesoid's value a candidate for flushing from the cache.- Returns:
trueifoid's value was unpinned from the cache;falseif the oid is not in the cache.
-
unpinAll
java.util.BitSet unpinAll(java.util.Collection<java.lang.Object> oids)
Unpin all oids from the cache.- Returns:
- the indexes of the unpinned oids
- See Also:
unpin(java.lang.Object)
-
unpinAll
void unpinAll(java.lang.Class<?> cls, boolean subs)Unpin all oids associaed with the given type from the cache.- Parameters:
subs- Whether to include subclasses.
-
writeLock
void writeLock()
Obtain a write lock on the cache.
-
writeUnlock
void writeUnlock()
Release the write lock on the cache.
-
addExpirationListener
void addExpirationListener(ExpirationListener listen)
Add a new expiration event listener to this cache.- Since:
- 0.2.5.0
-
removeExpirationListener
boolean removeExpirationListener(ExpirationListener listen)
Remove an expiration event listener from this cache.- Since:
- 0.2.5.0
-
close
void close()
Free the resources used by this cache.
-
getAll
java.util.Map<java.lang.Object,DataCachePCData> getAll(java.util.List<java.lang.Object> keys)
Gets objects from the caches for a given list of keys. The returned map has the same keys as the given keys. If the cache does not contain data for a specific key, the returned map still contains the key with a null value.
-
getPartition
DataCache getPartition(java.lang.String name, boolean create)
Gets the named partition. Note that a partition itself is another cache.- Parameters:
name- name of the given partition.create- if true optionally create a new partition.- Returns:
- a partition of the given name. Or null, if either no such partition exists or can not be created.
- Since:
- 2.0.0
-
getPartitionNames
java.util.Set<java.lang.String> getPartitionNames()
Gets the name of the known partitions.- Returns:
- empty set if no partition exists.
- Since:
- 2.0.0
-
isPartitioned
boolean isPartitioned()
Affirms if this cache maintains partitions.- Since:
- 2.0.0
-
getStatistics
CacheStatistics getStatistics()
Returns number of read/write request and cache hit ratio data.
-
getEvictOnBulkUpdate
boolean getEvictOnBulkUpdate()
Returns whether the the cache needs to be updated when bulk updates as executed. Defaults to true.
-
-