Package org.ametys.web.cache
Class CacheHelper
- java.lang.Object
-
- org.ametys.web.cache.CacheHelper
-
public final class CacheHelper extends Object
Helper for dealing with front-office cache.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CacheHelper.InvalidateCacheTimerTask
TimerTask
to invalidate site cache
-
Field Summary
Fields Modifier and Type Field Description private static Map<String,Long>
_cacheForPeriodOfValidity
(package private) static Map<String,Long>
_lastInvalidationDate
(package private) static Integer
_lockToken
(package private) static Timer
_timer
(package private) static Map<String,String>
_timerTasks
-
Constructor Summary
Constructors Modifier Constructor Description private
CacheHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static boolean
_checkResponse(byte[] bodyResponse)
private static String
_getContentType(org.apache.http.HttpResponse invalidateResponse)
private static long
_getPeriodOfValidity(Site site, String siteName)
private static byte[]
_getResponse(org.apache.http.HttpResponse response)
static List<Map<String,Object>>
callWS(String url, List<org.apache.http.NameValuePair> postParameters, org.slf4j.Logger logger)
Request the given URL on each configured front-office.static List<Map<String,Object>>
callWS(String url, org.slf4j.Logger logger)
Request the given URL on each configured front-office.static void
delayCacheInvalidation(String siteName, String urlWS, long periodOfValidity, org.slf4j.Logger logger)
Delay the cache invalidationstatic void
initializeTimerPeriod(String siteName)
Update the last invalidation cachestatic void
invalidateCache(Page page, org.slf4j.Logger logger)
Invalidates the front-office from the event observed.static void
invalidateCache(Page page, org.slf4j.Logger logger, boolean recursively)
Invalidates the front-office from the event observed.static void
invalidateCache(Site site, org.slf4j.Logger logger)
Invalidates the front-office from the event observed.static void
invalidateCache(Sitemap sitemap, org.slf4j.Logger logger)
Invalidates the front-office from the event observed.static boolean
isCacheValidityExpired(String siteName, long periodOfValidity)
Determines if cache validity is expired for given sitestatic void
testWS(String url, List<org.apache.http.NameValuePair> postParameters, org.slf4j.Logger logger)
Request the given URL on each configured front-office.static void
testWS(String url, org.slf4j.Logger logger)
Request the given URL on each configured front-office.
-
-
-
Field Detail
-
_lockToken
static Integer _lockToken
-
_lastInvalidationDate
static Map<String,Long> _lastInvalidationDate
-
_timerTasks
static Map<String,String> _timerTasks
-
_cacheForPeriodOfValidity
private static Map<String,Long> _cacheForPeriodOfValidity
-
-
Constructor Detail
-
CacheHelper
private CacheHelper()
-
-
Method Detail
-
testWS
public static void testWS(String url, org.slf4j.Logger logger) throws Exception
Request the given URL on each configured front-office.- Parameters:
url
- the url to be called.logger
- logger for traces.- Throws:
Exception
- if an error occurred.
-
testWS
public static void testWS(String url, List<org.apache.http.NameValuePair> postParameters, org.slf4j.Logger logger) throws Exception
Request the given URL on each configured front-office.- Parameters:
url
- the url to be called.postParameters
- submited valueslogger
- logger for traces.- Throws:
Exception
- if an error occurred.
-
callWS
public static List<Map<String,Object>> callWS(String url, org.slf4j.Logger logger) throws Exception
Request the given URL on each configured front-office.- Parameters:
url
- the url to be called.logger
- logger for traces.- Returns:
- The streams
- Throws:
Exception
- if an error occurred.
-
callWS
public static List<Map<String,Object>> callWS(String url, List<org.apache.http.NameValuePair> postParameters, org.slf4j.Logger logger) throws Exception
Request the given URL on each configured front-office.- Parameters:
url
- the url to be called.postParameters
- submitted valueslogger
- logger for traces.- Returns:
- The streams
- Throws:
Exception
- if an error occurred.
-
_checkResponse
private static boolean _checkResponse(byte[] bodyResponse) throws ParserConfigurationException, IllegalStateException, IOException, SAXException, TransformerException
-
_getResponse
private static byte[] _getResponse(org.apache.http.HttpResponse response) throws IllegalStateException, IOException
- Throws:
IllegalStateException
IOException
-
_getContentType
private static String _getContentType(org.apache.http.HttpResponse invalidateResponse)
-
invalidateCache
public static void invalidateCache(Site site, org.slf4j.Logger logger) throws Exception
Invalidates the front-office from the event observed.- Parameters:
site
- the site.logger
- logger for traces.- Throws:
Exception
- if an error occurs.
-
invalidateCache
public static void invalidateCache(Sitemap sitemap, org.slf4j.Logger logger) throws Exception
Invalidates the front-office from the event observed.- Parameters:
sitemap
- the sitemap.logger
- logger for traces.- Throws:
Exception
- if an error occurs.
-
invalidateCache
public static void invalidateCache(Page page, org.slf4j.Logger logger, boolean recursively) throws Exception
Invalidates the front-office from the event observed.- Parameters:
page
- the page.logger
- logger for traces.recursively
- true to invalidate the sub-pages- Throws:
Exception
- if an error occurs.
-
invalidateCache
public static void invalidateCache(Page page, org.slf4j.Logger logger) throws Exception
Invalidates the front-office from the event observed.- Parameters:
page
- the page.logger
- logger for traces.- Throws:
Exception
- if an error occurs.
-
_getPeriodOfValidity
private static long _getPeriodOfValidity(Site site, String siteName)
-
initializeTimerPeriod
public static void initializeTimerPeriod(String siteName)
Update the last invalidation cache- Parameters:
siteName
- the site name
-
isCacheValidityExpired
public static boolean isCacheValidityExpired(String siteName, long periodOfValidity)
Determines if cache validity is expired for given site- Parameters:
siteName
- the site nameperiodOfValidity
- the period of cache validity- Returns:
- true if cache validity is expired
-
delayCacheInvalidation
public static void delayCacheInvalidation(String siteName, String urlWS, long periodOfValidity, org.slf4j.Logger logger)
Delay the cache invalidation- Parameters:
siteName
- the site nameurlWS
- the WS url to be calledperiodOfValidity
- the period of cache validitylogger
- the logger
-
-