Package org.ametys.site
Class CacheAccessManager
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.site.CacheAccessManager
- All Implemented Interfaces:
Initializable
,Component
,Contextualizable
,LogEnabled
,Serviceable
,ThreadSafe
public class CacheAccessManager
extends AbstractLogEnabled
implements Component, Initializable, Serviceable, Contextualizable, ThreadSafe
Component that regulates access to the page cache.
-
Field Summary
Modifier and TypeFieldDescriptionprotected Context
The cocoon context.protected ConcurrentMap<String,
Boolean> A Map keeping record of whether the pages are cacheable or not.protected ConcurrentMap<String,
ReentrantLock> Map of page cache locks.protected BackOfficeRequestProxyExtensionPoint
The extension point for adding request headers in BO requeststatic final String
The avalon role. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
_isCacheable
(String pagePath) Get the cacheable status of a page from the back-office.void
contextualize
(Context context) void
boolean
isCacheable
(String pagePath) Tests if the page is cacheable.void
reset()
Resets all the local caches and locks.void
Remove a specified page path from the local cache and lock.void
service
(ServiceManager serviceManager) void
Release the lock associated with a page.Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
ROLE
The avalon role. -
_pageCacheable
A Map keeping record of whether the pages are cacheable or not. The key is the page path, the value indicates if the page is cacheable. -
_pageLocks
Map of page cache locks. The lock is acquired on the first call to the page, when the cache is empty, and released when the page is written into the cache. -
_context
The cocoon context. -
_requestProxyExtensionPoint
The extension point for adding request headers in BO request
-
-
Constructor Details
-
CacheAccessManager
public CacheAccessManager()
-
-
Method Details
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
isCacheable
Tests if the page is cacheable. If more than one thread call this method concurrently, only one tests the cacheability and (possibly) generates the corresponding resource. The concurrent threads are blocked until the page is known not to be cacheable, or known to be cacheable and put into the cache (inGeneratePageAction
).- Parameters:
pagePath
- the page path.- Returns:
- true if the page is cacheable, false otherwise.
- Throws:
IOException
- if an error occurs sending the cacheability request to the back-office.ServiceUnavailableException
- If the server is in maintenance- See Also:
-
unlock
Release the lock associated with a page.- Parameters:
pagePath
- the page path.
-
reset
Resets all the local caches and locks. -
resetPage
Remove a specified page path from the local cache and lock.- Parameters:
pagePath
- the page path.
-
_isCacheable
Get the cacheable status of a page from the back-office.- Parameters:
pagePath
- the page path.- Returns:
- true if the page is cacheable, false otherwise.
- Throws:
IOException
- in case of a problem or the connection was aborted
-