Class DataModifiedFilter

java.lang.Object
de.businesscode.bcdui.web.cacheControl.DataModifiedFilter
All Implemented Interfaces:
jakarta.servlet.Filter

public class DataModifiedFilter extends Object implements 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
  • Field Details

  • 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 interface jakarta.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

      protected String getReqScope(jakarta.servlet.http.HttpServletRequest httpReq)
      Derive the caching-scope from the request. In this case we just use the BindingSet as the scope
      Parameters:
      httpReq -
      Returns:
    • getScopeLastModified

      protected Long getScopeLastModified(String scope)
      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

      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 future
      Parameters:
      scope -
      Returns:
    • refreshScopes

      protected void refreshScopes()
      Read all scopes' information fresh from bcd_cache_scope
    • getSelectSql

      protected String 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 interface jakarta.servlet.Filter
      Throws:
      jakarta.servlet.ServletException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Filter