public interface ApplicationCache<K,V>
extends org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
Primordial interface for maintaining application cache. In contrast to other cache providers, this type of cache ensures type checking and provides efficient caching for a distributed system.
Implementations should provide appropriate methods to set their cache parameters (e.g. time-to-live) and/or force removal of entities before their normal expiration. These are not part of the AuthorizationCache interface contract because they vary depending on the type of caching system used (in-memory, disk, cluster, hybrid etc.).
Caching is generally only required in applications which do not maintain server-side state, such as remote clients or web services. The authentication credentials are then presented on each invocation and the overhead of accessing a database or other persistent storage mechanism to validate would be excessive. In this case, you would configure a cache to store the UserDetails information rather than loading it each time.
Note that the interface is declared abstract which doesn't make
any sense. But, it's just to notify the programmer that this type is not an
initialization/autowiring candidate. Interfaces/Classes extending/implementing this contract must
be initialized so as to support multiple types and instances of cache per container (as suited).
| Modifier and Type | Method and Description |
|---|---|
void |
evictFromCache(K key)
Removes the specified entry from the cache.
|
void |
flush()
Flushes the application cache (doesn't destroy it).
|
V |
getFromCache(K key)
Obtains a stored entry from the cache.
|
void |
initialize()
Initializes the application cache (doesn't create it).
|
void |
putInCache(K key,
V entry)
Places an entry in the cache.
|
void initialize()
Initializes the application cache (doesn't create it). Can make use of a data-store for pre-fetching already stored application data (if required) typically upon container restart.
Each type of application cache is initialized separately in order to maintain sanity and usage simplicity. Thus, please be advised that a cache type must be instantiated & initialized manually before use (manually just means that extra code is required for the same).
V getFromCache(K key)
Obtains a stored entry from the cache. Implementations must make sure not to throw an exception even if one occurs here.
key - the unique identifier to use for fetching the entry; be advised that the same
identifier must be used for saving the details into the cachevoid putInCache(K key, V entry)
Places an entry in the cache. The key is the identifier used to subsequently
retrieve the entry.
key - the key corresponding to which entry must be stored in the cacheentry - the object entry to place into the cachevoid evictFromCache(K key)
key is the identifier used to
remove the entry. If the entry is not found, the method should simply return (not throw an
exception).
Some cache implementations may not support eviction from the cache, in which case they should provide appropriate behavior to alter the token in either its documentation, via an exception, or through a log message.
key - the predefined key/identifier for evicting an entry from the cachevoid flush()
Flushes the application cache (doesn't destroy it). Note that flushing an application cache doesn't mean it is destroyed. It may just be reduced in size or cleared in order to re-claim memory.
Each type of application cache is flushed separately in order to maintain sanity and usage simplicity. Thus, please be advised that a cache type must be flushed & manually whenever required (manually just means that extra code is required for the same).
Copyright © 2015. All rights reserved.