Class DataModifiedFilter
java.lang.Object
de.businesscode.bcdui.web.cacheControl.DataModifiedFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
Cache control based on requested binding set name and data from scope_last_modified
If a request matches a certain scope, we check its last_refreshed and compare it against the request's If-Modified-Since-Header
If possible according to that, we send a 304 instead of forwarding to get new data
- If the scope was found in bcd_cache_scope, we are active, otherwise we do chain.doFilter
- If If-Modified-Since was sent, we compare that with the scopes scope_last_modified
- If If-Modified-Since was not sent or data was out-dated, we call chain.doFilter and set expires to earliest_next_modified if given
See bcdui4.DataModifiedFilter in web.xml for how to use
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Holds information about a scope like when data was actually refreshed last time and possibly when it may be refreshed earliest next time -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
protected boolean
didSend304
(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res) Check whether we can send a 304 and do so of possible Will send "Last-Modified" header if the scope was found.void
doFilter
(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res, jakarta.servlet.FilterChain chain) Handle the request brings 304 or operationprotected String
getReqScope
(jakarta.servlet.http.HttpServletRequest httpReq) Derive the caching-scope from the request.protected Long
getScopeLastModified
(String scope) Check whether we have a a last-modified for the scope and return it.protected String
The query to get the scops' datavoid
init
(jakarta.servlet.FilterConfig filterConfig) protected boolean
refreshNeeded
(String scope) Check whether we need to refresh the scope's data from bcd_cache_scope That is the case if refreshPeriodMs has passed since last update and earliestNextModified is not in the futureprotected void
Read all scopes' information fresh from bcd_cache_scope
-
Field Details
-
REFRESH_PERIOD_PARAM_NAME
- See Also:
-
REFRESH_PERIOD_DEFAULT
public static final int REFRESH_PERIOD_DEFAULT- See Also:
-
scopesLamos
-
logger
protected org.apache.logging.log4j.Logger logger -
lastRefreshedMs
protected long lastRefreshedMs -
refreshPeriodMs
protected long refreshPeriodMs -
utcCal
-
selectSQL
- See Also:
-
-
Constructor Details
-
DataModifiedFilter
public DataModifiedFilter()
-
-
Method Details
-
doFilter
public void doFilter(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException Handle the request brings 304 or operation- Specified by:
doFilter
in interfacejakarta.servlet.Filter
- Throws:
IOException
jakarta.servlet.ServletException
-
didSend304
protected boolean didSend304(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res) Check whether we can send a 304 and do so of possible Will send "Last-Modified" header if the scope was found. That triggers "If-Modified-Since" to be sent next time by the client- Parameters:
req
-res
-- Returns:
- false if 304 is not sufficient
-
getReqScope
Derive the caching-scope from the request. In this case we just use the BindingSet as the scope- Parameters:
httpReq
-- Returns:
-
getScopeLastModified
Check whether we have a a last-modified for the scope and return it. Returns -1 if there was no entry found- Parameters:
scope
-- Returns:
-
refreshNeeded
Check whether we need to refresh the scope's data from bcd_cache_scope That is the case if refreshPeriodMs has passed since last update and earliestNextModified is not in the future- Parameters:
scope
-- Returns:
-
refreshScopes
protected void refreshScopes()Read all scopes' information fresh from bcd_cache_scope -
getSelectSql
The query to get the scops' data- Returns:
-
init
public void init(jakarta.servlet.FilterConfig filterConfig) throws jakarta.servlet.ServletException - Specified by:
init
in interfacejakarta.servlet.Filter
- Throws:
jakarta.servlet.ServletException
-
destroy
public void destroy()- Specified by:
destroy
in interfacejakarta.servlet.Filter
-