Class BoundedCache
java.lang.Object
fc.util.cache.BoundedCache
In memory cache with the ability to specify an item bound/cache-limit
functionality. By default,the upper bound is Integer.MAX_VALUE.
Existing items are not automatically expired. They are only removed when a new item is added and the bound size is crossed. Which item is removed is according to BoundedCache.POLICY.
ThreadSafety: This class is thread safe and can be used by multiple threads concurrently.
- Version:
- 1.0 7/16/2010
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionBoundedCache
(Log log, String name, BoundedCache.Policy cachePolicy, int bound) Instantiates this class with the specified name, logger, policy and cache size.BoundedCache
(BoundedCache.Policy cachePolicy, int bound) Creates a memory cache with a system-assigned name, logger and the specified policy and bound. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
void
close()
Closes this cache, which makes all items in the cache unavailable.containsKey
(Object key) Returns the item for the specified key or null if the item does not exist.void
Removes the object specified by the key.Returns the item for the specified key or null if the item does not exist.getAll()
Returns the underlying storage read-only map for this cache.long
getBound()
Gets the current bound of this cache.boolean
isClosed()
Returns true if this cache has been closed, false otherwise.static void
Puts the item for the specified key.void
setBound
(int items) Sets the upper bound of this cache.toString()
-
Constructor Details
-
BoundedCache
Instantiates this class with the specified name, logger, policy and cache size.- Parameters:
name
- String denoting the name for this objectcachePolicy
- item removal policy when cache is fullbound
- the upper bound of this cache.logger
- a reference to aLog
-
BoundedCache
Creates a memory cache with a system-assigned name, logger and the specified policy and bound.
-
-
Method Details
-
setBound
Sets the upper bound of this cache. -
getBound
Gets the current bound of this cache. -
expire
-
containsKey
Returns the item for the specified key or null if the item does not exist. -
get
-
getAll
-
put
-
close
Closes this cache, which makes all items in the cache unavailable. Any items needed for later should be taken out of the cache before closing it.Note:, it is a good idea to close the cache once it's not needed, because it releases resources, including any internal threads spawned and used by this implementation.
-
isClosed
Returns true if this cache has been closed, false otherwise. -
clear
-
toString
-
main
-