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 classHolds 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 TypeMethodDescriptionvoiddestroy()protected booleandidSend304(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.voiddoFilter(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res, jakarta.servlet.FilterChain chain) Handle the request brings 304 or operationprotected StringgetReqScope(jakarta.servlet.http.HttpServletRequest httpReq) Derive the caching-scope from the request.protected LonggetScopeLastModified(String scope) Check whether we have a a last-modified for the scope and return it.protected StringThe query to get the scops' datavoidinit(jakarta.servlet.FilterConfig filterConfig) protected booleanrefreshNeeded(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 voidRead 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:
doFilterin interfacejakarta.servlet.Filter- Throws:
IOExceptionjakarta.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:
initin interfacejakarta.servlet.Filter- Throws:
jakarta.servlet.ServletException
-
destroy
public void destroy()- Specified by:
destroyin interfacejakarta.servlet.Filter
-