2015/07/26 - Apache DirectMemory has been retired.

For more information, please explore the Attic.

public interface

CacheService

implements Closeable
org.apache.directmemory.cache.CacheService<K, V>
Known Indirect Subclasses

Summary

Public Methods
abstract <T extends V> Pointer<V> allocate(K key, Class<T> type, int size)
Explicitly allocated a bunch of bytes in the cache using a given key and type and returns the created Pointer.
abstract void clear()
Clears the whole cache by removing all stored keys.
abstract void collectAll()
Tells the CacheService to collect and remove all expired AND least frequently used keys.
abstract void collectExpired()
Tells the CacheService to collect and remove all expired keys.
abstract void collectLFU()
Tells the CacheService to collect and remove all least frequently used keys.
abstract void dump()
Dumps information about the actual internal MemoryManagerService to the configured Logger with info loglevel.
abstract long entries()
Retrieves the count of the current entries.
abstract void free(K key)
Removes the key and frees the underlying memory area.
abstract void free(Pointer<V> pointer)
Removes the pointer and frees the underlying memory area.
abstract Map<K, Pointer<V>> getMap()
Retrieves a map of all available keys and their according Pointers.
abstract MemoryManagerService<V> getMemoryManager()
Retrieves the internally used MemoryManagerService implementation.
abstract Pointer<V> getPointer(K key)
Retrieves the accociated Pointer to the given key or null if no pointer was found.
abstract Serializer getSerializer()
Retrieves the internally used Serializer implementation.
abstract Pointer<V> put(K key, V value, int expiresIn)
Serializes and stored the given value using the key and sets the expiresIn value for the expiration of the key.
abstract Pointer<V> put(K key, V value)
Serializes and stored the given value using the key with no expiration value.
abstract Pointer<V> putByteArray(K key, byte[] payload)
Stored a preserialized payload with the given key with no expiration value.
abstract Pointer<V> putByteArray(K key, byte[] payload, long expiresIn)
Stored a preserialized payload with the given key.
abstract V retrieve(K key)
Retrieves the stored, deserialized value for key.
abstract byte[] retrieveByteArray(K key)
Retrieves the stored payload for key as a bytearray.
abstract void scheduleDisposalEvery(long period)
Schedules the disposal event with the given period in milliseconds.
abstract void scheduleDisposalEvery(long period, TimeUnit unit)
Schedules the disposal event with the given period with the given TimeUnit.
[Expand]
Inherited Methods
From interface java.io.Closeable

Public Methods

public abstract Pointer<V> allocate (K key, Class<T> type, int size)

Explicitly allocated a bunch of bytes in the cache using a given key and type and returns the created Pointer.

Parameters
key The key to store as
type The datatype of the underlying data
size The size to allocate for this pointer

public abstract void clear ()

Clears the whole cache by removing all stored keys. It is up to the underlying MemoryManagerService implementation to free allocated memory or not.

public abstract void collectAll ()

Tells the CacheService to collect and remove all expired AND least frequently used keys. In most cases this is automatically handled by scheduling a disposal interval using scheduleDisposalEvery(long) and there are very rare cases where this needs to be called manually.

public abstract void collectExpired ()

Tells the CacheService to collect and remove all expired keys. In most cases this is automatically handled by scheduling a disposal interval using scheduleDisposalEvery(long) and there are very rare cases where this needs to be called manually.

public abstract void collectLFU ()

Tells the CacheService to collect and remove all least frequently used keys. This operation could possibly clear the whole cache if there were no recent actions. In most cases this is automatically handled by scheduling a disposal interval using scheduleDisposalEvery(long) and there are very rare cases where this needs to be called manually.

public abstract void dump ()

Dumps information about the actual internal MemoryManagerService to the configured Logger with info loglevel.

public abstract long entries ()

Retrieves the count of the current entries.

Returns
  • Number of entries

public abstract void free (K key)

Removes the key and frees the underlying memory area.

Parameters
key The key to remove

public abstract void free (Pointer<V> pointer)

Removes the pointer and frees the underlying memory area.

Parameters
pointer The pointer to remove

public abstract Map<K, Pointer<V>> getMap ()

Retrieves a map of all available keys and their according Pointers. It is up to the CacheService implementation if the retrieved map is threadsafe or not. The standard implementation uses a ConcurrentHashMap.

Returns
  • A mapping of keys to their according pointers

public abstract MemoryManagerService<V> getMemoryManager ()

Retrieves the internally used MemoryManagerService implementation.

Returns
  • The used memory manager

public abstract Pointer<V> getPointer (K key)

Retrieves the accociated Pointer to the given key or null if no pointer was found.

Parameters
key The key to retrieve
Returns
  • The pointer of the key or null if key was not found

public abstract Serializer getSerializer ()

Retrieves the internally used Serializer implementation.

Returns
  • The used serializer

public abstract Pointer<V> put (K key, V value, int expiresIn)

Serializes and stored the given value using the key and sets the expiresIn value for the expiration of the key. If not enough space found to store the payload the returned pointer is null.

Parameters
key The key to save the value with
value The value to serialize and store
expiresIn The expiration delay
Returns
  • The created pointer to directly retrieve the payload or null if not enough space was found

public abstract Pointer<V> put (K key, V value)

Serializes and stored the given value using the key with no expiration value. If not enough space found to store the payload the returned pointer is null.

Parameters
key The key to save the value with
value The value to serialize and store
Returns
  • The created pointer to directly retrieve the payload or null if not enough space was found

public abstract Pointer<V> putByteArray (K key, byte[] payload)

Stored a preserialized payload with the given key with no expiration value. If not enough space found to store the payload the returned pointer is null.

Parameters
key The key to save the payload with
payload The preserialized payload as bytearray
Returns
  • The created pointer to directly retrieve the payload or null if not enough space was found

public abstract Pointer<V> putByteArray (K key, byte[] payload, long expiresIn)

Stored a preserialized payload with the given key. The expiration is set to the given expiresIn value in milliseconds. If not enough space found to store the payload the returned pointer is null.

Parameters
key The key to save the payload with
payload The preserialized payload as bytearray
expiresIn The expiration delay
Returns
  • The created pointer to directly retrieve the payload or null if not enough space was found

public abstract V retrieve (K key)

Retrieves the stored, deserialized value for key. If no pointer is found for the given key null is returned.

Parameters
key The key to retrieve
Returns
  • The deserialized value or null if key was not found

public abstract byte[] retrieveByteArray (K key)

Retrieves the stored payload for key as a bytearray. If no pointer is found for the given key null is returned.

Parameters
key The key to retrieve
Returns
  • The payload as bytearray or null if key was not found

public abstract void scheduleDisposalEvery (long period)

Schedules the disposal event with the given period in milliseconds.

Parameters
period The time period in milliseconds

public abstract void scheduleDisposalEvery (long period, TimeUnit unit)

Schedules the disposal event with the given period with the given TimeUnit.

Parameters
period The time period
unit The period's timeunit