Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
prevent loading of content from the cache when retrieval with IFFRESH is used and cache is stale. Should speed up snippet generation when cache strategy is IFFRESH.
Michael Peter Christenc3db01541054
diff --git a/source/de/anomic/crawler/Cache.java b/source/de/anomic/crawler/Cache.javaindex 6afd3f659..7ec9f8902 100644--- a/source/de/anomic/crawler/Cache.java+++ b/source/de/anomic/crawler/Cache.java@@ -297,6 +297,16 @@ public final class Cache {}}+ public static boolean hasContent(final byte[] hash) {+ // load the url as resource from the cache+ try {+ return fileDB.containsKey(hash);+ } catch (final OutOfMemoryError e) {+ Log.logException(e);+ return false;+ }+ }+/*** removed response header and cached content from the database* @param urldiff --git a/source/net/yacy/repository/LoaderDispatcher.java b/source/net/yacy/repository/LoaderDispatcher.javaindex fe0f84a5b..0a219d93e 100644--- a/source/net/yacy/repository/LoaderDispatcher.java+++ b/source/net/yacy/repository/LoaderDispatcher.java@@ -201,8 +201,7 @@ public final class LoaderDispatcher {// now see if there is a cache entryfinal ResponseHeader cachedResponse = (url.isLocal()) ? null : Cache.getResponseHeader(url.hash());- final byte[] content = (cachedResponse == null) ? null : Cache.getContent(url.hash());- if (cachedResponse != null && content != null) {+ if (cachedResponse != null && Cache.hasContent(url.hash())) {// yes we have the content// create request header values and a response object because we need that@@ -218,26 +217,32 @@ public final class LoaderDispatcher {cachedResponse,crawlProfile,true,- content);+ null);// check which caching strategy shall be usedif (cacheStrategy == CacheStrategy.IFEXIST || cacheStrategy == CacheStrategy.CACHEONLY) {// well, just take the cache and don't care about freshness of the content- this.log.logInfo("cache hit/useall for: " + url.toNormalform(true, false));- return response;+ final byte[] content = Cache.getContent(url.hash());+ if (content != null) {+ this.log.logInfo("cache hit/useall for: " + url.toNormalform(true, false));+ response.setContent(content);+ return response;+ }}// now the cacheStrategy must be CACHE_STRATEGY_IFFRESH, that means we should do a proxy freshness testassert cacheStrategy == CacheStrategy.IFFRESH : "cacheStrategy = " + cacheStrategy;if (response.isFreshForProxy()) {- this.log.logInfo("cache hit/fresh for: " + url.toNormalform(true, false));- return response;+ final byte[] content = Cache.getContent(url.hash());+ if (content != null) {+ this.log.logInfo("cache hit/fresh for: " + url.toNormalform(true, false));+ response.setContent(content);+ return response;+ }}this.log.logInfo("cache hit/stale for: " + url.toNormalform(true, false));} else if (cachedResponse != null) {this.log.logWarning("HTCACHE contained response header, but not content for url " + url.toNormalform(true, false));- } else if (content != null) {- this.log.logWarning("HTCACHE contained content, but not response header for url " + url.toNormalform(true, false));}}