void init(ExtendletConfig config, ExtendletLoader<V> loader) { _webctx = config.getExtendletContext(); _cache = new ResourceCache<String, V>(loader, 16); _cache.setMaxSize(1024); _cache.setLifetime(60 * 60 * 1000); // 1hr final int checkPeriod = loader.getCheckPeriod(); _cache.setCheckPeriod(checkPeriod >= 0 ? checkPeriod : 60 * 60 * 1000); // 1hr }
// called by Provider InputStream getResourceAsStream(HttpServletRequest request, String path, boolean locate) throws IOException, ServletException { if (locate) path = Servlets.locate(_webctx.getServletContext(), request, path, _webctx.getLocator()); if (_cache.getCheckPeriod() >= 0) { // Due to Web server might cache the result, we use URL if possible try { URL url = _webctx.getResource(path); if (url != null) return url.openStream(); } catch (Throwable ex) { log.warningBriefly("Unable to read from URL: " + path, ex); } } // Note: _webctx will handle the renaming for debugJS (.src.js) return _webctx.getResourceAsStream(path); }
/** Sets whether to generate JS files that is easy to debug. */ public void setDebugJS(boolean debugJS) { _debugJS = Boolean.valueOf(debugJS); if (_cache != null) _cache.clear(); }