Package org.wso2.carbon.mediator.cache
Class CacheMediator
- java.lang.Object
-
- org.apache.synapse.mediators.AbstractMediator
-
- org.wso2.carbon.mediator.cache.CacheMediator
-
- All Implemented Interfaces:
org.apache.synapse.aspects.AspectConfigurable
,org.apache.synapse.debug.constructs.EnclosedInlinedSequence
,org.apache.synapse.ManagedLifecycle
,org.apache.synapse.Mediator
,org.apache.synapse.SynapseArtifact
public class CacheMediator extends org.apache.synapse.mediators.AbstractMediator implements org.apache.synapse.ManagedLifecycle, org.apache.synapse.debug.constructs.EnclosedInlinedSequence
If a request comes to this class it creates and hash of the request and if the hash has a CachedResponse associated with it the mediator will return the response without going to the backend. Otherwise it will pass on the request to the next mediator.
-
-
Constructor Summary
Constructors Constructor Description CacheMediator(CacheManager cacheManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
void
exposeInvalidator(org.apache.synapse.MessageContext msgCtx)
Exposes the whole mediator cache through jmx MBean.DigestGenerator
getDigestGenerator()
This method gives the DigestGenerator to evaluate the hash values of incoming messages.String
getHashGenerator()
This returns the hash generator used to evaluate the hash value.String[]
getHeadersToExcludeInHash()
This method gives array of headers that would be excluded when hashing.String[]
getHeadersToIncludeInHash()
This method gives array of headers that would be included when hashing.String[]
getHTTPMethodsToCache()
This method gives the HTTP method that needs to be cached.String
getId()
This method returns the id of the cache configuration.String
getImplementationType()
This method returns the cache implementation type.org.apache.synapse.Mediator
getInlineSequence(org.apache.synapse.config.SynapseConfiguration synCfg, int inlinedSeqIdentifier)
int
getInMemoryCacheSize()
This method gives the size of the messages to be cached in memory.int
getMaxMessageSize()
This method gives the maximum size of the messages to be cached in bytes.com.google.common.cache.LoadingCache<String,CachableResponse>
getMediatorCache()
Creates default cache to keep mediator cache.String
getOnCacheHitRef()
This method gives reference to the onCacheHit sequence to be executed.org.apache.synapse.mediators.base.SequenceMediator
getOnCacheHitSequence()
This method gives SequenceMediator to be executed.String
getProtocolType()
String
getResponseCodes()
String
getScope()
This method returns the scope of the cache.long
getTimeout()
This method gives the timeout period in milliseconds.void
init(org.apache.synapse.core.SynapseEnvironment se)
boolean
isAddAgeHeaderEnabled()
This method returns whether an Age header needs to be included or not.boolean
isCacheControlEnabled()
This method returns whether cache-control is enabled or not.boolean
isCollector()
This method gives whether the mediator should be in the incoming path or in the outgoing path as a boolean.boolean
isPreviousCacheImplementation()
This method returns whether this represents the previous cache implementation or not.boolean
mediate(org.apache.synapse.MessageContext synCtx)
void
setAddAgeHeaderEnabled(boolean addAgeHeaderEnabled)
This method sets whether an Age header needs to be included or not.void
setCacheControlEnabled(boolean cacheControlEnabled)
This method sets whether cache-control is enabled or not.void
setCollector(boolean collector)
This method sets whether the mediator should be in the incoming path or in the outgoing path as a boolean.void
setDigestGenerator(DigestGenerator digestGenerator)
This method sets the DigestGenerator to evaluate the hash values of incoming messages.void
setHashGenerator(String hashGenerator)
This method sets the hash generator class.void
setHeadersToExcludeInHash(String... headersToExcludeInHash)
This method sets the array of headers that would be excluded when hashing.void
setHeadersToIncludeInHash(String... headersToIncludeInHash)
This method sets the array of headers that would be included when hashing.void
setHTTPMethodsToCache(String... hTTPMethodToCache)
This sets the HTTP method that needs to be cached.void
setId(String id)
This method sets the id of the cache configuration.void
setImplementationType(String implementationType)
This method sets the cache implementation type.void
setInMemoryCacheSize(int inMemoryCacheSize)
This method sets the size of the messages to be cached in memory.void
setMaxMessageSize(int maxMessageSize)
This method sets the maximum size of the messages to be cached in bytes.void
setOnCacheHitRef(String onCacheHitRef)
This method sets reference to the onCacheHit sequence to be executed.void
setOnCacheHitSequence(org.apache.synapse.mediators.base.SequenceMediator onCacheHitSequence)
This method sets SequenceMediator to be executed.void
setPreviousCacheImplementation(boolean previousCacheImplementation)
This method sets whether this represents the previous cache implementation or not.void
setProtocolType(String protocolType)
This method sets protocolType of the messages.void
setResponseCodes(String responseCodes)
This method sets the response codes that needs to be cached.void
setScope(String scope)
This method sets the scope of the cache.void
setTimeout(long timeout)
This method sets the timeout period as milliseconds.-
Methods inherited from class org.apache.synapse.mediators.AbstractMediator
auditLog, auditWarn, configure, disableStatistics, disableTracing, divertMediationRoute, enableStatistics, enableTracing, getAspectConfiguration, getCommentsList, getDescription, getInputType, getLastSequenceFaultHandler, getLog, getMediatorName, getMediatorPosition, getOutputType, getRegisteredMediationFlowPoint, getShortDescription, getTraceState, getType, handleException, handleException, isBreakPoint, isContentAltering, isContentAware, isSkipEnabled, isStatisticsEnable, isTraceOn, isTraceOrDebugOn, isTracingEnabled, registerMediationFlowPoint, reportCloseStatistics, reportOpenStatistics, setBreakPoint, setCommentsList, setComponentStatisticsId, setDescription, setEffectiveTraceState, setMediatorPosition, setShortDescription, setSkipEnabled, setTraceState, shouldCaptureTracing, shouldTrace, shouldTrace, traceOrDebug, traceOrDebugWarn, unregisterMediationFlowPoint
-
-
-
-
Constructor Detail
-
CacheMediator
public CacheMediator(CacheManager cacheManager)
-
-
Method Detail
-
init
public void init(org.apache.synapse.core.SynapseEnvironment se)
- Specified by:
init
in interfaceorg.apache.synapse.ManagedLifecycle
-
destroy
public void destroy()
- Specified by:
destroy
in interfaceorg.apache.synapse.ManagedLifecycle
-
mediate
public boolean mediate(org.apache.synapse.MessageContext synCtx)
- Specified by:
mediate
in interfaceorg.apache.synapse.Mediator
-
getMediatorCache
public com.google.common.cache.LoadingCache<String,CachableResponse> getMediatorCache()
Creates default cache to keep mediator cache.- Returns:
- global cache
-
getInlineSequence
public org.apache.synapse.Mediator getInlineSequence(org.apache.synapse.config.SynapseConfiguration synCfg, int inlinedSeqIdentifier)
- Specified by:
getInlineSequence
in interfaceorg.apache.synapse.debug.constructs.EnclosedInlinedSequence
-
exposeInvalidator
public void exposeInvalidator(org.apache.synapse.MessageContext msgCtx)
Exposes the whole mediator cache through jmx MBean.
-
getDigestGenerator
public DigestGenerator getDigestGenerator()
This method gives the DigestGenerator to evaluate the hash values of incoming messages.- Returns:
- DigestGenerator used evaluate hash values.
-
setDigestGenerator
public void setDigestGenerator(DigestGenerator digestGenerator)
This method sets the DigestGenerator to evaluate the hash values of incoming messages.- Parameters:
digestGenerator
- DigestGenerator to be set to evaluate hash values.
-
getTimeout
public long getTimeout()
This method gives the timeout period in milliseconds.- Returns:
- timeout in milliseconds
-
setTimeout
public void setTimeout(long timeout)
This method sets the timeout period as milliseconds.- Parameters:
timeout
- millisecond timeout period to be set.
-
isCollector
public boolean isCollector()
This method gives whether the mediator should be in the incoming path or in the outgoing path as a boolean.- Returns:
- boolean true if incoming path false if outgoing path.
-
setCollector
public void setCollector(boolean collector)
This method sets whether the mediator should be in the incoming path or in the outgoing path as a boolean.- Parameters:
collector
- boolean value to be set as collector.
-
getHeadersToExcludeInHash
public String[] getHeadersToExcludeInHash()
This method gives array of headers that would be excluded when hashing.- Returns:
- array of headers to exclude from hashing
-
setHeadersToExcludeInHash
public void setHeadersToExcludeInHash(String... headersToExcludeInHash)
This method sets the array of headers that would be excluded when hashing.- Parameters:
headersToExcludeInHash
- array of headers to exclude from hashing.
-
getHeadersToIncludeInHash
public String[] getHeadersToIncludeInHash()
This method gives array of headers that would be included when hashing.- Returns:
- array of headers to included in hashing
-
setHeadersToIncludeInHash
public void setHeadersToIncludeInHash(String... headersToIncludeInHash)
This method sets the array of headers that would be included when hashing.- Parameters:
headersToIncludeInHash
- array of headers to include in hashing.
-
getOnCacheHitSequence
public org.apache.synapse.mediators.base.SequenceMediator getOnCacheHitSequence()
This method gives SequenceMediator to be executed.- Returns:
- sequence mediator to be executed.
-
setOnCacheHitSequence
public void setOnCacheHitSequence(org.apache.synapse.mediators.base.SequenceMediator onCacheHitSequence)
This method sets SequenceMediator to be executed.- Parameters:
onCacheHitSequence
- sequence mediator to be set.
-
getOnCacheHitRef
public String getOnCacheHitRef()
This method gives reference to the onCacheHit sequence to be executed.- Returns:
- reference to the onCacheHit sequence.
-
setOnCacheHitRef
public void setOnCacheHitRef(String onCacheHitRef)
This method sets reference to the onCacheHit sequence to be executed.- Parameters:
onCacheHitRef
- reference to the onCacheHit sequence to be set.
-
getInMemoryCacheSize
public int getInMemoryCacheSize()
This method gives the size of the messages to be cached in memory.- Returns:
- memory cache size in bytes.
-
setInMemoryCacheSize
public void setInMemoryCacheSize(int inMemoryCacheSize)
This method sets the size of the messages to be cached in memory.- Parameters:
inMemoryCacheSize
- value(number of bytes) to be set as memory cache size.
-
getHTTPMethodsToCache
public String[] getHTTPMethodsToCache()
This method gives the HTTP method that needs to be cached.- Returns:
- the HTTP method to be cached
-
setHTTPMethodsToCache
public void setHTTPMethodsToCache(String... hTTPMethodToCache)
This sets the HTTP method that needs to be cached.- Parameters:
hTTPMethodToCache
- the HTTP method to be cached
-
getProtocolType
public String getProtocolType()
- Returns:
- the protocol type of the messages
-
setProtocolType
public void setProtocolType(String protocolType)
This method sets protocolType of the messages.- Parameters:
protocolType
- protocol type of the messages.
-
getResponseCodes
public String getResponseCodes()
- Returns:
- The regex expression of the HTTP response code of the messages to be cached
-
setResponseCodes
public void setResponseCodes(String responseCodes)
This method sets the response codes that needs to be cached.- Parameters:
responseCodes
- the response codes to be cached in regex form.
-
getMaxMessageSize
public int getMaxMessageSize()
This method gives the maximum size of the messages to be cached in bytes.- Returns:
- maximum size of the messages to be cached in bytes.
-
setMaxMessageSize
public void setMaxMessageSize(int maxMessageSize)
This method sets the maximum size of the messages to be cached in bytes.- Parameters:
maxMessageSize
- maximum size of the messages to be set in bytes.
-
isCacheControlEnabled
public boolean isCacheControlEnabled()
This method returns whether cache-control is enabled or not.- Returns:
- whether cache-control is enabled or not.
-
setCacheControlEnabled
public void setCacheControlEnabled(boolean cacheControlEnabled)
This method sets whether cache-control is enabled or not.- Parameters:
cacheControlEnabled
- whether cache-control is enabled or not.
-
isAddAgeHeaderEnabled
public boolean isAddAgeHeaderEnabled()
This method returns whether an Age header needs to be included or not.- Returns:
- whether an Age header needs to be included or not.
-
setAddAgeHeaderEnabled
public void setAddAgeHeaderEnabled(boolean addAgeHeaderEnabled)
This method sets whether an Age header needs to be included or not.- Parameters:
addAgeHeaderEnabled
- whether an Age header needs to be included or not.
-
setId
public void setId(String id)
This method sets the id of the cache configuration.- Parameters:
id
- id of the cache configuration
-
getId
public String getId()
This method returns the id of the cache configuration.- Returns:
- id of the cache configuration
-
setHashGenerator
public void setHashGenerator(String hashGenerator)
This method sets the hash generator class.- Parameters:
hashGenerator
- hash generator used to evaluate the hash value
-
getHashGenerator
public String getHashGenerator()
This returns the hash generator used to evaluate the hash value.- Returns:
- hash generator used to evaluate the hash value
-
setScope
public void setScope(String scope)
This method sets the scope of the cache.- Parameters:
scope
- scope of the cache
-
getScope
public String getScope()
This method returns the scope of the cache.- Returns:
- the scope of the cache
-
setImplementationType
public void setImplementationType(String implementationType)
This method sets the cache implementation type.- Parameters:
implementationType
- cache implementation type
-
getImplementationType
public String getImplementationType()
This method returns the cache implementation type.- Returns:
- cache implementation type
-
isPreviousCacheImplementation
public boolean isPreviousCacheImplementation()
This method returns whether this represents the previous cache implementation or not.- Returns:
- whether this represents the previous cache implementation or not
-
setPreviousCacheImplementation
public void setPreviousCacheImplementation(boolean previousCacheImplementation)
This method sets whether this represents the previous cache implementation or not.- Parameters:
previousCacheImplementation
- whether this represents the previous cache implementation or not
-
-