public void init ( ) throws ServletException { FilterConfig config = getFilterConfig ( ) ; // Default don't delete cache files on exit (persistent cache) boolean deleteCacheOnExit = "TRUE" . equalsIgnoreCase ( config . getInitParameter ( "deleteCacheOnExit" ) ) ; // Default expiry time 10 minutes int expiryTime = 10 * 60 * 1000 ; String expiryTimeStr = config . getInitParameter ( "expiryTime" ) ; if ( ! StringUtil . isEmpty ( expiryTimeStr ) ) { try { // TODO: This is insane.. :-P Let the expiry time be in minutes or seconds.. expiryTime = Integer . parseInt ( expiryTimeStr ) ; } catch ( NumberFormatException e ) { throw new ServletConfigException ( "Could not parse expiryTime: " + e . toString ( ) , e ) ; } } // Default max mem cache size 10 MB int memCacheSize = 10 ; String memCacheSizeStr = config . getInitParameter ( "memCacheSize" ) ; if ( ! StringUtil . isEmpty ( memCacheSizeStr ) ) { try { memCacheSize = Integer . parseInt ( memCacheSizeStr ) ; } catch ( NumberFormatException e ) { throw new ServletConfigException ( "Could not parse memCacheSize: " + e . toString ( ) , e ) ; } } int maxCachedEntites = 10000 ; try { cache = new HTTPCache ( getTempFolder ( ) , expiryTime , memCacheSize * 1024 * 1024 , maxCachedEntites , deleteCacheOnExit , new ServletContextLoggerAdapter ( getFilterName ( ) , getServletContext ( ) ) ) { @ Override protected File getRealFile ( CacheRequest pRequest ) { String contextRelativeURI = ServletUtil . getContextRelativeURI ( ( ( ServletCacheRequest ) pRequest ) . getRequest ( ) ) ; String path = getServletContext ( ) . getRealPath ( contextRelativeURI ) ; if ( path != null ) { return new File ( path ) ; } return null ; } } ; log ( "Created cache: " + cache ) ; } catch ( IllegalArgumentException e ) { throw new ServletConfigException ( "Could not create cache: " + e . toString ( ) , e ) ; } }
Initializes the filter