public interface MemoryCache
Modifier and Type | Interface and Description |
---|---|
static interface |
MemoryCache.CacheListener
Provides the interface for cache clients to be notified of key events.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object key,
Cacheable clientObject)
Attempts to add the
Cacheable object referenced by the key. |
boolean |
add(Object key,
Object clientObject,
long objectSize)
Attempts to add the object
clientObject , with size objectSize and referred to by
key to the cache. |
void |
addCacheListener(MemoryCache.CacheListener listener)
Adds a new
cacheListener , which will be sent notification whenever an entry is removed from the
cache. |
void |
clear()
Empties the cache.
|
boolean |
contains(Object key)
Discovers whether or not this cache contains the object referenced by
key. |
long |
getCapacity()
Retrieves the maximum size of the cache.
|
long |
getFreeCapacity()
Retrieves the available space for storing new items.
|
long |
getLowWater()
Retrieves the low water value of the
MemoryCache . |
String |
getName() |
int |
getNumObjects()
Retrieve the number of items stored in the
MemoryCache . |
Object |
getObject(Object key)
Retrieves the requested item from the cache.
|
long |
getUsedCapacity()
Retrieves the amount of used
MemoryCache space. |
void |
remove(Object key)
Remove an object from the MemoryCache referenced by
key . |
void |
removeCacheListener(MemoryCache.CacheListener listener)
Removes a
CacheListener , notifications of events will no longer be sent to this listener. |
void |
setCapacity(long capacity)
Sets the maximum capacity for this
cache . |
void |
setLowWater(long loWater)
Sets the new low water capacity value for this
MemoryCache . |
void |
setName(String name) |
boolean add(Object key, Cacheable clientObject)
Cacheable
object referenced by the key. No explicit size value is required as
this method queries the Cacheable to discover the size.
This method should be declared synchronized
when it is implemented.key
- an object used to reference the cached item.clientObject
- the item to be cached.Cacheable
boolean add(Object key, Object clientObject, long objectSize)
clientObject
, with size objectSize
and referred to by
key
to the cache. objectSize
is the size in cache units, but is not checked for
accuracy. Returns whether or not the add was successful.
Note that the size passed in may be used, rather than the real size of the object. In some implementations, the
accuracy of the space used calls will depend on the collection of these sizes, rather than actual size.
This method should be declared synchronized
when it is implemented.key
- an object used to reference the cached item.clientObject
- the item to be cached.objectSize
- the size of the item in cache units.void addCacheListener(MemoryCache.CacheListener listener)
cacheListener
, which will be sent notification whenever an entry is removed from the
cache.listener
- the new MemoryCache.CacheListener
void clear()
clear()
on a MemoryCache
, calls relating to used
capacity and number of items should return zero and the free capacity should be the maximum capacity.
This method should be declared synchronized
when it is implemented and should notify all
CacheListener
s of entries removed.boolean contains(Object key)
key. Currently no interface exists
to discover if an object resides in the cache by referencing itself.
key
- the key which the object is referenced by.long getCapacity()
MemoryCache
.long getFreeCapacity()
long getLowWater()
MemoryCache
. When a MemoryCache
runs out of free
space, it must remove some items if it wishes to add any more. It continues removing items until the low water
level is reached. Not every MemoryCache
necessarily uses the low water system, so this may not
return a useful value.MemoryCache
.String getName()
int getNumObjects()
MemoryCache
.Object getObject(Object key)
key
is null or the item is not found, this method
returns null.key
- an Object
used to represent the item to retrieve.Object
if found, null otherwise.long getUsedCapacity()
MemoryCache
space. The value returned is in cache units.void remove(Object key)
key
. If the object is already absent, this
method simply returns without indicating the absence.key
- an Object
used to represent the item to remove.void removeCacheListener(MemoryCache.CacheListener listener)
CacheListener
, notifications of events will no longer be sent to this listener.listener
- the cache listener to remove.void setCapacity(long capacity)
cache
. This capacity has no impact on the number of items stored
in the MemoryCache
, except that every item must have a positive size. Generally the used capacity is
the total of the sizes of all stored items.capacity
- the new capacity.void setLowWater(long loWater)
MemoryCache
. When a MemoryCache
runs out
of free space, it must remove some items if it wishes to add any more. It continues removing items until the low
water level is reached. Not every MemoryCache
necessarily uses the low water system, so this method
may not have any actual effect in some implementations.loWater
- the new low water value.void setName(String name)