public interface CacheWriter
If configured for a cache, CacheWriter's methods will be called on a cache operation. A cache put will cause a CacheWriter write and a cache remove will cause a writer delete.
Implementers should create an implementation which handles storing and deleting to an underlying resource.
It's important to note that the operations that are handled by the CacheWriter
don't have any guaranteed ordering in write-behind mode.
The processing ordering can be different than the scheduling ordering, so your application needs to be written with this
in mind. More information in the CacheWriter chapter of the documentation.
The manner upon which a CacheWriter is actually called is determined by the CacheWriterConfiguration
that is set up for cache
that is using the CacheWriter.
See the CacheWriter chapter in the documentation for more information on how to use writers.
Modifier and Type | Method and Description |
---|---|
CacheWriter |
clone(Ehcache cache)
Creates a clone of this writer.
|
void |
delete(CacheEntry entry)
Delete the cache entry from the store
|
void |
deleteAll(Collection<CacheEntry> entries)
Remove data and keys from the underlying store for the given collection of keys, if present.
|
void |
dispose()
Providers may be doing all sorts of exotic things and need to be able to clean up on
dispose.
|
void |
init()
Notifies writer to initialise themselves.
|
void |
throwAway(Element element,
SingleOperationType operationType,
RuntimeException e)
This method will be called, whenever an Element couldn't be handled by the writer and all
the
retryAttempts have been tried. |
void |
write(Element element)
Write the specified value under the specified key to the underlying store.
|
void |
writeAll(Collection<Element> elements)
Write the specified Elements to the underlying store.
|
CacheWriter clone(Ehcache cache) throws CloneNotSupportedException
Implementations should throw CloneNotSupportedException if they do not support clone but that will stop them from being used with defaultCache.
CloneNotSupportedException
- if the extension could not be cloned.void init()
This method is called during the Cache's initialise method after it has changed it's status to alive. Cache operations are legal in this method. If you register a cache writer manually after a cache has been initialised already, this method will be called on the cache writer as soon as it has been registered.
Note that if you reuse cache writer instances or create a factory that returns the
same cache writer instance as a singleton, your init
method should be able
to handle that situation. Unless you perform this multiple usage of a cache writer yourself,
Ehcache will not do this though. So in the majority of the use cases, you don't need to do
anything special.
CacheException
void dispose() throws CacheException
Cache operations are illegal when this method is called. The cache itself is partly disposed when this method is called.
CacheException
void write(Element element) throws CacheException
element
- the element to be writtenCacheException
void writeAll(Collection<Element> elements) throws CacheException
elements
- the Elements to be writtenCacheException
void delete(CacheEntry entry) throws CacheException
entry
- the cache entry that is used for the delete operationCacheException
void deleteAll(Collection<CacheEntry> entries) throws CacheException
entries
- the entries that have been removed from the cacheCacheException
void throwAway(Element element, SingleOperationType operationType, RuntimeException e)
retryAttempts
have been tried.
When batching is enabled all the elements in the failing batch will be passed to this methods
Try to not throw RuntimeExceptions from this method. Should an Exception occur, it will be logged, but the element will be lost anyways.
element
- the Element that triggered the failure, or one of the elements part of the batch that failedoperationType
- the operation we tried to executee
- the RuntimeException thrown by the Writer when the last retry attempt was being executedCopyright © 2003–2016 Terracotta, Inc.. All rights reserved.