long getSize() { long result = CACHE_ENTRY_SIZE; if (getContentLength() <= objectMaxSizeBytes) { result += getContentLength(); } return result; } }
@Override public int compare(CachedResource cr1, CachedResource cr2) { long nc1 = cr1.getNextCheck(); long nc2 = cr2.getNextCheck(); // Oldest resource should be first (so iterator goes from oldest to // youngest. if (nc1 == nc2) { return 0; } else if (nc1 > nc2) { return -1; } else { return 1; } } }
private void removeCacheEntry(String path, boolean updateSize) { // With concurrent calls for the same path, the entry is only removed // once and the cache size is only updated (if required) once. CachedResource cachedResource = resourceCache.remove(path); if (cachedResource != null && updateSize) { long delta = cachedResource.getSize(); size.addAndGet(-delta); } }
if (cacheEntry != null && !cacheEntry.validateResources(useClassLoaderResources)) { removeCacheEntry(path); cacheEntry = null; CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(), objectMaxSizeBytes, useClassLoaderResources); cacheEntry.validateResources(useClassLoaderResources); long delta = cacheEntry.getSize(); size.addAndGet(delta); cacheEntry.validateResources(useClassLoaderResources); return cacheEntry.getWebResources();
if (cacheEntry != null && !cacheEntry.validateResource(useClassLoaderResources)) { removeCacheEntry(path); cacheEntry = null; CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(), objectMaxSizeBytes, useClassLoaderResources); cacheEntry.validateResource(useClassLoaderResources); long delta = cacheEntry.getSize(); size.addAndGet(delta); cacheEntry.validateResource(useClassLoaderResources);
webResource = root.getResourceInternal( webAppPath, useClassLoaderResources); getLastModified(); getContentLength(); nextCheck = ttl + now; if (webResource.getLastModified() != getLastModified() || webResource.getContentLength() != getContentLength()) { return false;
if (resource == null || resource.getLastModified() < lastModified) { IOUtils.closeQuietly(input); resource = new CachedResource(url.getFile(), data, headerFields, lastModified); // I use url.getFile() to store the file on my hard drive. cache.addCachedResource(url, resource);
private long evict(long targetSize, Iterator<CachedResource> iter) { long now = System.currentTimeMillis(); long newSize = size.get(); while (newSize > targetSize && iter.hasNext()) { CachedResource resource = iter.next(); // Don't expire anything that has been checked within the TTL if (resource.getNextCheck() > now) { continue; } // Remove the entry from the cache removeCacheEntry(resource.getWebappPath()); newSize = size.get(); } return newSize; }
if (cacheEntry != null && !cacheEntry.validate(useClassLoaderResources)) { removeCacheEntry(path, true); cacheEntry = null; new CachedResource(root, path, getTtl(), objectMaxSizeBytes); cacheEntry.validate(useClassLoaderResources); long delta = cacheEntry.getSize(); size.addAndGet(delta); cacheEntry.validate(useClassLoaderResources);
@Override public InputStream getInputStream() { byte[] content = getContent(); if (content == null) { // Can't cache InputStreams return webResource.getInputStream(); } return new ByteArrayInputStream(content); }
if (cacheEntry != null && !cacheEntry.validateResources(useClassLoaderResources)) { removeCacheEntry(path); cacheEntry = null; CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(), objectMaxSizeBytes, useClassLoaderResources); cacheEntry.validateResources(useClassLoaderResources); long delta = cacheEntry.getSize(); size.addAndGet(delta); cacheEntry.validateResources(useClassLoaderResources); return cacheEntry.getWebResources();
if (cacheEntry != null && !cacheEntry.validateResource(useClassLoaderResources)) { removeCacheEntry(path); cacheEntry = null; CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(), objectMaxSizeBytes, useClassLoaderResources); cacheEntry.validateResource(useClassLoaderResources); long delta = cacheEntry.getSize(); size.addAndGet(delta); cacheEntry.validateResource(useClassLoaderResources);
webResource = root.getResourceInternal( webAppPath, useClassLoaderResources); getLastModified(); getContentLength(); nextCheck = ttl + now; if (webResource.getLastModified() != getLastModified() || webResource.getContentLength() != getContentLength()) { return false;
private long evict(long targetSize, Iterator<CachedResource> iter) { long now = System.currentTimeMillis(); long newSize = size.get(); while (newSize > targetSize && iter.hasNext()) { CachedResource resource = iter.next(); // Don't expire anything that has been checked within the TTL if (resource.getNextCheck() > now) { continue; } // Remove the entry from the cache removeCacheEntry(resource.getWebappPath(), true); newSize = size.get(); } return newSize; }
@Override public InputStream getInputStream() { byte[] content = getContent(); if (content == null) { // Can't cache InputStreams return webResource.getInputStream(); } return new ByteArrayInputStream(content); }
webResource = root.getResourceInternal( webAppPath, useClassLoaderResources); getLastModified(); getContentLength(); nextCheck = ttl + now; if (webResource.getLastModified() != getLastModified() || webResource.getContentLength() != getContentLength()) { return false;
private long evict(long targetSize, Iterator<CachedResource> iter) { long now = System.currentTimeMillis(); long newSize = size.get(); while (newSize > targetSize && iter.hasNext()) { CachedResource resource = iter.next(); // Don't expire anything that has been checked within the TTL if (resource.getNextCheck() > now) { continue; } // Remove the entry from the cache removeCacheEntry(resource.getWebappPath()); newSize = size.get(); } return newSize; }
long getSize() { long result = CACHE_ENTRY_SIZE; if (getContentLength() <= objectMaxSizeBytes) { result += getContentLength(); } return result; } }
void removeCacheEntry(String path) { // With concurrent calls for the same path, the entry is only removed // once and the cache size is only updated (if required) once. CachedResource cachedResource = resourceCache.remove(path); if (cachedResource != null) { long delta = cachedResource.getSize(); size.addAndGet(-delta); } }
@Override public int compare(CachedResource cr1, CachedResource cr2) { long nc1 = cr1.getNextCheck(); long nc2 = cr2.getNextCheck(); // Oldest resource should be first (so iterator goes from oldest to // youngest. if (nc1 == nc2) { return 0; } else if (nc1 > nc2) { return -1; } else { return 1; } } }