public abstract class AbstractCacheEngine extends HeadEngine
This class is an abstraction of an engine
which reads from a cache the nuts associated to a workflow to be processed.
If an entry exists, then the nuts are returned and no more engine is executed.
Otherwise, the chain is executed and the result is put in the cache.
The engine could be configured to be in best effort mode. In that case, if the result of the request is not already in the cache, it just call only the mandatory operations in the chain to deliver as fast as possible a response to the client. All operations are done asynchronously and result is added to the cache when finished. This mode allows to not increase response time for the user when he is the first to send the request even if nuts are not fully processed.
The cache itself is abstract here and it needs to be provided by subclass.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractCacheEngine.CacheResult
Represents the value to be cached.
|
Constructor and Description |
---|
AbstractCacheEngine(Boolean work,
Boolean be)
Builds a new engine.
|
Modifier and Type | Method and Description |
---|---|
EngineType |
getEngineType()
Gets the type of engine.
|
abstract AbstractCacheEngine.CacheResult |
getFromCache(EngineRequest.Key request)
Gets the list of nuts associated to the specified request from the cache.
|
List<ConvertibleNut> |
internalParse(EngineRequest request)
Internal method that parses eventually called by
NodeEngine.parse(EngineRequest) method during its invocation. |
ConvertibleNut |
parse(EngineRequest request,
String path)
Parses the given request and returns the nut associated to the given path.
|
abstract void |
putToCache(EngineRequest.Key request,
AbstractCacheEngine.CacheResult nuts)
Puts the given list of nuts associated to the specified request to the cache.
|
abstract void |
removeFromCache(EngineRequest.Key request)
Removes the given list of nuts associated to the specified request from the cache.
|
Boolean |
works()
Returns a flag indicating if the engine is configured to do something or not.
|
parse, runChains
public List<ConvertibleNut> internalParse(EngineRequest request) throws WuicException
Internal method that parses eventually called by NodeEngine.parse(EngineRequest)
method during its invocation.
internalParse
in class Engine
request
- the request with files to parseWuicException
- if any kind of error occurspublic Boolean works()
Returns a flag indicating if the engine is configured to do something or not.
public EngineType getEngineType()
Gets the type of engine.
getEngineType
in class Engine
public ConvertibleNut parse(EngineRequest request, String path) throws WuicException
Parses the given request and returns the nut associated to the given path.
parse
in class HeadEngine
request
- the requestpath
- the nut nameWuicException
- if request could not be executed successfullypublic abstract void putToCache(EngineRequest.Key request, AbstractCacheEngine.CacheResult nuts)
Puts the given list of nuts associated to the specified request to the cache.
request
- the request keynuts
- the nutspublic abstract void removeFromCache(EngineRequest.Key request)
Removes the given list of nuts associated to the specified request from the cache.
request
- request keypublic abstract AbstractCacheEngine.CacheResult getFromCache(EngineRequest.Key request)
Gets the list of nuts associated to the specified request from the cache.
request
- the request keyCopyright © 2012-2015. All Rights Reserved.