Package lumis.portal.page.cache
Class PageCacheManager
- java.lang.Object
-
- lumis.portal.page.cache.PageCacheManager
-
- All Implemented Interfaces:
IPageCacheManager
,IPageCacheManagerSPI
public class PageCacheManager extends Object implements IPageCacheManagerSPI
Manager for page cache information.- Since:
- 4.0.0
- Version:
- $Revision: 24477 $ $Date: 2021-04-28 11:30:36 -0300 (Wed, 28 Apr 2021) $
-
-
Field Summary
Fields Modifier and Type Field Description static Long
lastExcessiveCleaningTimestamp
static String
PAGE_CACHE_MANAGER_LANGUAGE_FILENAME_PREFIX
-
Fields inherited from interface lumis.portal.page.cache.IPageCacheManager
CLEAR_CACHE_CHANGE_TYPE_DELETE, CLEAR_CACHE_CHANGE_TYPE_UPDATE, PAGE_CACHE_GEN_STATE_DISABLED, PAGE_CACHE_GEN_STATE_ENABLED
-
-
Constructor Summary
Constructors Constructor Description PageCacheManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clearAllHTMLCache(ITransaction transaction)
Clears all page HTML cache.void
clearCacheByChannelIds(SessionConfig sessionConfig, Collection<String> channelIds, Map<String,String[]> parameters, int changeType, ITransaction transaction)
Clear the cache of the pages within the specified channels recursively.void
clearCacheByPagesIds(SessionConfig sessionConfig, Collection<String> pagesIds, Map<String,String[]> parameters, Locale locale, int changeType, ITransaction transaction)
Clear the cache of the specified pages.void
clearPageCacheErrors(Collection<String> pageCacheIds, ITransaction transaction)
Clear page cache errors in the database.void
delete(SessionConfig sessionConfig, String pageCacheId, ITransaction transaction)
Delete a page cache.protected void
deleteHtmlFiles(PageCacheConfig pageCache, boolean deleteShadowCacheHtml)
Delete the HTML cache files for the specified path.protected void
deleteHtmlFiles(IWebsite website, String filePath, boolean deleteShadowCacheHtml)
Delete the HTML cache files for the specified path.protected PageCacheManager.HttpAccessResult
doHttpAccess(URL url, String cookies, PageCacheConfig pageCacheConfig)
void
enablePageCacheByPageParam(String paramName, String paramValue, Locale locale)
Enable page cache by a given page parameter name-value pair and locale.void
expirePageCache(PageCacheConfig pageCacheConfig)
Expires a singlePageCacheConfig
PageCacheConfig
generateNextPage(lumis.portal.page.cache.GenerationSelectStrategy generationSelectStrategy)
Generates next outdated page cache, according to the given strategy.PageCacheConfig
generatePage(String pageCacheId)
Generates a page cache.protected void
generatePage(PageCacheConfig pageCacheConfig)
PageCacheConfig
get(String pageCacheId)
Returns a page cache given its identifier.protected PageCacheConfig
getGenerationLock(String pageCacheId)
Gets a lock for generating a cached page.protected PageCacheConfig
getNextPageForGeneration(lumis.portal.page.cache.GenerationSelectStrategy generationSelectStrategy)
Returns the next page cache to be generated.int
getPageCacheGenerationState(SessionConfig sessionConfig, ITransaction transaction)
Deprecated.void
initializePageCacheConfigurations()
Initializes page cache related configurations.boolean
isPageCacheGenerationEnabled()
Indicates if the page cache generation is globally enabled.void
pageCacheMissed(String pageCacheId, boolean forImmediateUse)
Indicates a miss in the page cache occurred.String
processHTMLForPageCache(String htmlContent, PageCacheConfig pageCache)
Processes a HTML code for storing for a page cache.void
recalculateCaches(String channelId)
Recalculates the attributes for the caches in the portal area inside the specified channel.protected void
releaseGenerationLock(PageCacheConfig pageCacheConfig, IPageCacheManager.GenerationOutcome outcome)
Releases the generation lock for a cached page.void
resetExpiredGeneratingPages()
Resets all pages that have been in the generating state for more than 30 minutes.void
setPageCacheGenerationState(SessionConfig sessionConfig, int state, ITransaction transaction)
Sets the page cache generation state.void
updateCachedFilesLastModifiedDate(SessionConfig sessionConfig, PageConfig pageConfig, Locale locale, Date lastModifiedDate, ITransaction transaction)
Updates the last modified date of the cached files that match the given pageId and locale.String
waitForGeneration(String pageCacheId, long timeout)
Waits for the generation of a page cache.void
waitForPagesReadyToGenerate(long timeout, boolean forImmediateUseOnly)
Waits for new pages to be ready to be generated.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface lumis.portal.page.cache.IPageCacheManager
processHTMLForPageCache
-
-
-
-
Field Detail
-
lastExcessiveCleaningTimestamp
public static Long lastExcessiveCleaningTimestamp
-
PAGE_CACHE_MANAGER_LANGUAGE_FILENAME_PREFIX
public static final String PAGE_CACHE_MANAGER_LANGUAGE_FILENAME_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
expirePageCache
public void expirePageCache(PageCacheConfig pageCacheConfig) throws PortalException
Expires a singlePageCacheConfig
- Specified by:
expirePageCache
in interfaceIPageCacheManager
- Parameters:
pageCacheConfig
- the page cache to expired.- Throws:
PortalException
- Since:
- 6.1.0
-
waitForGeneration
public String waitForGeneration(String pageCacheId, long timeout) throws PortalException, InterruptedException
Description copied from interface:IPageCacheManager
Waits for the generation of a page cache.- Specified by:
waitForGeneration
in interfaceIPageCacheManager
- Parameters:
pageCacheId
- the page cache identifier.timeout
- maximum time to wait.- Returns:
- the generated page content.
- Throws:
InterruptedException
- if the thread was interrupted.PortalException
-
waitForPagesReadyToGenerate
public void waitForPagesReadyToGenerate(long timeout, boolean forImmediateUseOnly) throws InterruptedException
Description copied from interface:IPageCacheManager
Waits for new pages to be ready to be generated.- Specified by:
waitForPagesReadyToGenerate
in interfaceIPageCacheManager
- Parameters:
timeout
- maximum time to wait.forImmediateUseOnly
- if true, wait until a page for immediate use is ready to generate. If false, wait until any page is ready to generate.- Throws:
InterruptedException
- if the thread was interrupted.
-
doHttpAccess
protected PageCacheManager.HttpAccessResult doHttpAccess(URL url, String cookies, PageCacheConfig pageCacheConfig) throws UnsupportedEncodingException, IOException, PortalException, lumis.portal.page.cache.ContentNotPublishedException
- Throws:
UnsupportedEncodingException
IOException
PortalException
lumis.portal.page.cache.ContentNotPublishedException
-
generatePage
protected void generatePage(PageCacheConfig pageCacheConfig) throws ManagerException, PortalException, lumis.portal.page.cache.ContentNotPublishedException
- Throws:
ManagerException
PortalException
lumis.portal.page.cache.ContentNotPublishedException
-
generateNextPage
public PageCacheConfig generateNextPage(lumis.portal.page.cache.GenerationSelectStrategy generationSelectStrategy) throws PortalException, lumis.portal.page.cache.ContentNotPublishedException
Generates next outdated page cache, according to the given strategy. If the generation lock could not be obtained, the page is not generated.- Parameters:
generationSelectStrategy
- contains informations for the strategy for selecting the next to be generated.- Returns:
- the generated page cache information, or
null
if the generation lock could not be obtained or if there is no outdated page (as specified in the parameters). - Throws:
lumis.portal.page.cache.ContentNotPublishedException
PortalException
- Since:
- 14.0.0
-
generatePage
public PageCacheConfig generatePage(String pageCacheId) throws PortalException
Description copied from interface:IPageCacheManager
Generates a page cache. If the generation lock could not be obtained, the page is not generated.- Specified by:
generatePage
in interfaceIPageCacheManager
- Parameters:
pageCacheId
- the page cache identifier.- Returns:
- the generated page cache information, or null if the generation lock could not be obtained.
- Throws:
PortalException
-
deleteHtmlFiles
protected void deleteHtmlFiles(IWebsite website, String filePath, boolean deleteShadowCacheHtml)
Delete the HTML cache files for the specified path.- Parameters:
website
- the website from where the file will be deleted.filePath
- the relative cache file path.deleteShadowCacheHtml
- iftrue
, the shadow cache file is also deleted.- Since:
- 6.2.0
-
deleteHtmlFiles
protected void deleteHtmlFiles(PageCacheConfig pageCache, boolean deleteShadowCacheHtml)
Delete the HTML cache files for the specified path.- Parameters:
pageCache
- the page cache that will have its files deleted.deleteShadowCacheHtml
- iftrue
, the shadow cache file is also deleted.- Throws:
IOException
- Since:
- 6.2.0
-
delete
public void delete(SessionConfig sessionConfig, String pageCacheId, ITransaction transaction) throws ManagerException, PortalException
Description copied from interface:IPageCacheManager
Delete a page cache.- Specified by:
delete
in interfaceIPageCacheManager
- Throws:
ManagerException
PortalException
-
get
public PageCacheConfig get(String pageCacheId) throws PortalException
Description copied from interface:IPageCacheManager
Returns a page cache given its identifier.- Specified by:
get
in interfaceIPageCacheManager
- Parameters:
pageCacheId
- the page cache identifier.- Returns:
- the persistent page cache instance.
- Throws:
PortalObjectNotFoundException
- if no page cache with the given identifier was found.PortalException
-
processHTMLForPageCache
public String processHTMLForPageCache(String htmlContent, PageCacheConfig pageCache) throws PortalException
Description copied from interface:IPageCacheManager
Processes a HTML code for storing for a page cache.- Specified by:
processHTMLForPageCache
in interfaceIPageCacheManager
- Parameters:
htmlContent
- HTML code.pageCache
- the page cache the code will be used in.- Returns:
- the processed HTML code.
- Throws:
PortalException
-
clearCacheByPagesIds
public void clearCacheByPagesIds(SessionConfig sessionConfig, Collection<String> pagesIds, Map<String,String[]> parameters, Locale locale, int changeType, ITransaction transaction) throws PortalException
Description copied from interface:IPageCacheManager
Clear the cache of the specified pages. This method clears the specified pages cache after the transaction commits.- Specified by:
clearCacheByPagesIds
in interfaceIPageCacheManager
- Parameters:
sessionConfig
- the user session information.pagesIds
- a collection of the pages identifiers.parameters
- the page parameters. Used to filter which caches are cleared.locale
- specifies the locale to which the cache clearing is to be applied. May be null to indicate any locale.changeType
- the cause of the cache clear. Must be one of the CLEAR_CACHE_CHANGE_TYPE_* constants.transaction
- the transaction for persistence access.- Throws:
PortalException
-
clearCacheByChannelIds
public void clearCacheByChannelIds(SessionConfig sessionConfig, Collection<String> channelIds, Map<String,String[]> parameters, int changeType, ITransaction transaction) throws PortalException
Description copied from interface:IPageCacheManager
Clear the cache of the pages within the specified channels recursively. This method will clear the specified pages cache after the transaction commits.- Specified by:
clearCacheByChannelIds
in interfaceIPageCacheManager
- Parameters:
sessionConfig
- the user session information.parameters
- the page parameters. Used to filter which caches are cleared.changeType
- the cause of the cache clear. Must be one of the CLEAR_CACHE_CHANGE_TYPE_* constants.transaction
- the transaction for persistence access.- Throws:
PortalException
-
getPageCacheGenerationState
@Deprecated public int getPageCacheGenerationState(SessionConfig sessionConfig, ITransaction transaction) throws PortalException
Deprecated.Description copied from interface:IPageCacheManager
Returns whether page cache generation is enabled or not- Specified by:
getPageCacheGenerationState
in interfaceIPageCacheManager
- Returns:
- Throws:
PortalException
-
isPageCacheGenerationEnabled
public boolean isPageCacheGenerationEnabled()
Description copied from interface:IPageCacheManager
Indicates if the page cache generation is globally enabled.- Specified by:
isPageCacheGenerationEnabled
in interfaceIPageCacheManager
- Returns:
true
if enabled,false
otherwise.
-
setPageCacheGenerationState
public void setPageCacheGenerationState(SessionConfig sessionConfig, int state, ITransaction transaction) throws PortalException
Sets the page cache generation state.The session provided must have MANAGE_CACHE permission at the portal level in order to execute this method successfully.
- Specified by:
setPageCacheGenerationState
in interfaceIPageCacheManager
- Parameters:
sessionConfig
-state
-transaction
-- Throws:
PortalException
- Since:
- 4.0.11
-
getGenerationLock
protected PageCacheConfig getGenerationLock(String pageCacheId) throws PortalException
Gets a lock for generating a cached page.To get a lock successfully, the page cache status must be
PageCacheConfig.STATUS_OUTDATED
.If successful, the page cache status will be changed to
PageCacheConfig.STATUS_GENERATING
.- Parameters:
pageCacheId
- the page cache identifier.- Returns:
- the locked page cache, or null if it could not be locked for generation.
- Throws:
PortalException
-
releaseGenerationLock
protected void releaseGenerationLock(PageCacheConfig pageCacheConfig, IPageCacheManager.GenerationOutcome outcome) throws PortalException
Releases the generation lock for a cached page.According to the outcome argument, the following happens:
IPageCacheManager.GenerationOutcome.SUCCESS
: If the current status isgenerating
, it is changed toupdated
, else it is changed tooutdated
. Thenumber of errors
is reset to zero.IPageCacheManager.GenerationOutcome.CANCEL
: The status is changed tooutdated
.IPageCacheManager.GenerationOutcome.ERROR
: Thenumber of errors
is incremented, and the status is changed tooutdated
oroutdated with error
, depending on whether the number of errors reachedmax error count
.
- Parameters:
pageCacheConfig
- the page cache.outcome
- the generation outcome.newStatus
- the new status if the current status is generating.- Throws:
PortalException
- Since:
- 4.1.0
-
updateCachedFilesLastModifiedDate
public void updateCachedFilesLastModifiedDate(SessionConfig sessionConfig, PageConfig pageConfig, Locale locale, Date lastModifiedDate, ITransaction transaction) throws PortalException
Description copied from interface:IPageCacheManager
Updates the last modified date of the cached files that match the given pageId and locale.- Specified by:
updateCachedFilesLastModifiedDate
in interfaceIPageCacheManager
- Parameters:
sessionConfig
- the user session information.pageConfig
- the portal page.locale
- locale for which the cached files needs to be modified.lastModifiedDate
- date to which the matched files must be modified to.transaction
- the transaction for persistence access.- Throws:
PortalException
-
pageCacheMissed
public void pageCacheMissed(String pageCacheId, boolean forImmediateUse) throws PortalException
Description copied from interface:IPageCacheManager
Indicates a miss in the page cache occurred. This provokes an asynchronous page cache generation and causes an increase in its priority due to the interest in accessing it.- Specified by:
pageCacheMissed
in interfaceIPageCacheManager
- Parameters:
pageCacheId
- the page cache identifier.forImmediateUse
- if true, indicates that the missed page cache is required for immediate use. This will greater boost the priority to generate the corresponding page cache.- Throws:
PortalException
-
getNextPageForGeneration
protected PageCacheConfig getNextPageForGeneration(lumis.portal.page.cache.GenerationSelectStrategy generationSelectStrategy) throws PortalException
Returns the next page cache to be generated. It is locked for generation before being returned.- Parameters:
generationSelectStrategy
- the strategy to select the cache to be generated.- Returns:
- the next page cache to be generated, or null if no suitable page was found.
- Throws:
PortalException
- Since:
- 6.0.0
- See Also:
#getGenerationLock(PageCacheConfig)
,#releaseGenerationLock(PageCacheConfig, int)
-
clearAllHTMLCache
public void clearAllHTMLCache(ITransaction transaction) throws PortalException
Description copied from interface:IPageCacheManager
Clears all page HTML cache.- Specified by:
clearAllHTMLCache
in interfaceIPageCacheManager
- Parameters:
transaction
- the transaction for persistence access.- Throws:
PortalException
-
clearPageCacheErrors
public void clearPageCacheErrors(Collection<String> pageCacheIds, ITransaction transaction) throws PortalException
Description copied from interface:IPageCacheManager
Clear page cache errors in the database. It is locked for update before being updated.- Specified by:
clearPageCacheErrors
in interfaceIPageCacheManager
- Parameters:
pageCacheIds
- the page cache identifiers.transaction
- the transaction for persistence access.- Throws:
PortalException
-
initializePageCacheConfigurations
public void initializePageCacheConfigurations()
Initializes page cache related configurations.Populates the database with the page cache related default configurations.
- Since:
- 6.0.0
-
recalculateCaches
public void recalculateCaches(String channelId) throws PortalException
Recalculates the attributes for the caches in the portal area inside the specified channel.- Parameters:
channelId
- the channel identifier.- Throws:
PortalException
- Since:
- 6.0.0
-
resetExpiredGeneratingPages
public void resetExpiredGeneratingPages() throws PortalException
Description copied from interface:IPageCacheManagerSPI
Resets all pages that have been in the generating state for more than 30 minutes.- Specified by:
resetExpiredGeneratingPages
in interfaceIPageCacheManagerSPI
- Throws:
PortalException
-
enablePageCacheByPageParam
public void enablePageCacheByPageParam(String paramName, String paramValue, Locale locale)
Enable page cache by a given page parameter name-value pair and locale.- Parameters:
paramName
- the parameter name.paramValue
- the parameter value.locale
- the locale.- Since:
- 10.2.0
-
-