@Override public void serve(final Sender sender, final HttpServerExchange exchange, final IoCallback completionCallback) { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache == null) { underlyingResource.serve(sender, exchange, completionCallback); final Long length = getContentLength(); if (length == null || length > cachingResourceManager.getMaxFileSize()) { underlyingResource.serve(sender, exchange, completionCallback); return; entry = dataCache.add(cacheKey, length.intValue(), cachingResourceManager.getMaxAge()); } else { entry = existing;
Resource preCompressed = encoded.getResource(newPath); if (preCompressed != null) { return new ContentEncodedResource(preCompressed, encoding.getName()); try { preCompressed = encoded.getResource(newPath); if (preCompressed != null) { return new ContentEncodedResource(preCompressed, encoding.getName()); encoded.invalidate(newPath); final Resource encodedResource = encoded.getResource(newPath); return new ContentEncodedResource(encodedResource, encoding.getName()); } finally {
@Override public void serveRange(Sender sender, HttpServerExchange exchange, long start, long end, IoCallback completionCallback) { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache == null) { ((RangeAwareResource)underlyingResource).serveRange(sender, exchange, start, end, completionCallback); final Long length = getContentLength(); if (length == null || length > cachingResourceManager.getMaxFileSize()) { ((RangeAwareResource)underlyingResource).serveRange(sender, exchange, start, end, completionCallback); return;
resourceManager = new CachingResourceManager(servletContainer.getFileCacheMetadataSize(), servletContainer.getFileCacheMaxFileSize(), servletContainer.getBufferCache(), resourceManager, servletContainer.getFileCacheTimeToLive() == null ? (explodedDeployment ? 2000 : -1) : servletContainer.getFileCacheTimeToLive()); if(externalResources != null && !externalResources.isEmpty()) {
public boolean checkStillValid() { if (nextMaxAgeCheck > 0) { long time = System.currentTimeMillis(); if (time > nextMaxAgeCheck) { nextMaxAgeCheck = time + cachingResourceManager.getMaxAge(); if (!underlyingResource.getLastModified().equals(lastModifiedDate)) { return false; } } } return true; }
@Override public void handleChanges(Collection<ResourceChangeEvent> changes) { for(ResourceChangeEvent change : changes) { invalidate(change.getResource()); } } });
public void invalidate() { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache != null) { dataCache.remove(cacheKey); } }
@Override public void serveRange(Sender sender, HttpServerExchange exchange, long start, long end, IoCallback completionCallback) { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache == null) { ((RangeAwareResource)underlyingResource).serveRange(sender, exchange, start, end, completionCallback); final Long length = getContentLength(); if (length == null || length > cachingResourceManager.getMaxFileSize()) { ((RangeAwareResource)underlyingResource).serveRange(sender, exchange, start, end, completionCallback); return;
public static HttpHandler resource(String prefix, int cacheTime) { ResourceManager resourceManager = null; if (Env.LOCAL == Env.get()) { String path = Paths.get(AssetsConfig.assetsRoot(), prefix).toString(); log.debug("using local file resource manager {}", path); resourceManager = new FileResourceManager(new File(path), 1024 * 1024); } else { log.debug("using classpath file resource manager"); ResourceManager classPathManager = new ClassPathResourceManager(CustomHandlers.class.getClassLoader(), prefix); resourceManager = new CachingResourceManager(100, 65536, new DirectBufferCache(1024, 10, 10480), classPathManager, cacheTime); } ResourceHandler handler = new ResourceHandler(resourceManager); handler.setCacheTime(cacheTime); return handler; }
public CachedResource(final CachingResourceManager cachingResourceManager, final Resource underlyingResource, final String path) { this.cachingResourceManager = cachingResourceManager; this.underlyingResource = underlyingResource; this.directory = underlyingResource.isDirectory(); this.lastModifiedDate = underlyingResource.getLastModified(); if (lastModifiedDate != null) { this.lastModifiedDateString = DateUtils.toDateString(lastModifiedDate); } else { this.lastModifiedDateString = null; } this.eTag = underlyingResource.getETag(); this.name = underlyingResource.getName(); this.cacheKey = new CacheKey(cachingResourceManager, underlyingResource.getCacheKey()); if (cachingResourceManager.getMaxAge() > 0) { nextMaxAgeCheck = System.currentTimeMillis() + cachingResourceManager.getMaxAge(); } else { nextMaxAgeCheck = -1; } }
return resource; } else { invalidate(path);
@Override public Long getContentLength() { //we always use the underlying size unless the data is cached in the buffer cache //to prevent a mis-match between size on disk and cached size final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache == null) { return underlyingResource.getContentLength(); } final DirectBufferCache.CacheEntry existing = dataCache.get(cacheKey); if(existing == null || !existing.enabled()) { return underlyingResource.getContentLength(); } //we only return the return (long)existing.size(); }
@Override public void serve(final Sender sender, final HttpServerExchange exchange, final IoCallback completionCallback) { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache == null) { underlyingResource.serve(sender, exchange, completionCallback); final Long length = getContentLength(); if (length == null || length > cachingResourceManager.getMaxFileSize()) { underlyingResource.serve(sender, exchange, completionCallback); return; entry = dataCache.add(cacheKey, length.intValue(), cachingResourceManager.getMaxAge()); } else { entry = existing;
@Override public void serveRange(Sender sender, HttpServerExchange exchange, long start, long end, IoCallback completionCallback) { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache == null) { ((RangeAwareResource)underlyingResource).serveRange(sender, exchange, start, end, completionCallback); final Long length = getContentLength(); if (length == null || length > cachingResourceManager.getMaxFileSize()) { underlyingResource.serve(sender, exchange, completionCallback); return;
Resource preCompressed = encoded.getResource(newPath); if (preCompressed != null) { return new ContentEncodedResource(preCompressed, encoding.getName()); try { preCompressed = encoded.getResource(newPath); if (preCompressed != null) { return new ContentEncodedResource(preCompressed, encoding.getName()); encoded.invalidate(newPath); final Resource encodedResource = encoded.getResource(newPath); return new ContentEncodedResource(encodedResource, encoding.getName()); } finally {
new CachingResourceManager(1000, 1L, null, new FileResourceManager(new File(path), 1 * 1024 * 1024), 250); String[] welcomeFiles = new String[] { "index.html", "index.html", "default.html", "default.htm" };
public boolean checkStillValid() { if (nextMaxAgeCheck > 0) { long time = System.currentTimeMillis(); if (time > nextMaxAgeCheck) { nextMaxAgeCheck = time + cachingResourceManager.getMaxAge(); if (!underlyingResource.getLastModified().equals(lastModifiedDate)) { return false; } } } return true; }
@Override public void handleChanges(Collection<ResourceChangeEvent> changes) { for(ResourceChangeEvent change : changes) { invalidate(change.getResource()); } } });
public void invalidate() { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache != null) { dataCache.remove(cacheKey); } }
@Override public void serve(final Sender sender, final HttpServerExchange exchange, final IoCallback completionCallback) { final DirectBufferCache dataCache = cachingResourceManager.getDataCache(); if(dataCache == null) { underlyingResource.serve(sender, exchange, completionCallback); final Long length = getContentLength(); if (length == null || length > cachingResourceManager.getMaxFileSize()) { underlyingResource.serve(sender, exchange, completionCallback); return; entry = dataCache.add(cacheKey, length.intValue(), cachingResourceManager.getMaxAge()); } else { entry = existing;