You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nutch.apache.org by og...@yahoo.com on 2006/05/28 19:38:40 UTC
Re: [Nutch-cvs] svn commit: r409869 - in /lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org: ./ apache/ apache/nutch/ apache/nutch/webapp/ apache/nutch/webapp/controller/
Spotted a reference to "NutchReferehPolicy();" :
EntryRefreshPolicy policy=new NutchReferehPolicy();
Typo?
Otis
----- Original Message ----
From: siren@apache.org
To: nutch-commits@lucene.apache.org
Sent: Saturday, May 27, 2006 4:36:56 PM
Subject: [Nutch-cvs] svn commit: r409869 - in /lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org: ./ apache/ apache/nutch/ apache/nutch/webapp/ apache/nutch/webapp/controller/
Author: siren
Date: Sat May 27 13:36:55 2006
New Revision: 409869
URL: http://svn.apache.org/viewvc?rev=409869&view=rev
Log:
added some sample plugins
Added:
lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/
lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/
lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/
lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/
lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/CacheManager.java
lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/controller/
lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/controller/CachingSearchController.java
Added: lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/CacheManager.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/CacheManager.java?rev=409869&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/CacheManager.java (added)
+++ lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/CacheManager.java Sat May 27 13:36:55 2006
@@ -0,0 +1,65 @@
+package org.apache.nutch.webapp;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.nutch.webapp.common.Search;
+
+import com.opensymphony.oscache.base.Cache;
+import com.opensymphony.oscache.base.CacheEntry;
+import com.opensymphony.oscache.base.EntryRefreshPolicy;
+import com.opensymphony.oscache.base.NeedsRefreshException;
+
+/**
+ * CacheManager for
+ */
+public class CacheManager {
+
+ static final String CACHE_KEY="cache";
+
+ class NutchReferehPolicy implements EntryRefreshPolicy {
+ private static final long serialVersionUID = 1L;
+
+ public boolean needsRefresh(CacheEntry arg0) {
+ return false;
+ }
+ }
+
+ EntryRefreshPolicy policy=new NutchReferehPolicy();
+
+ Cache cache;
+
+ protected CacheManager(){
+ cache=new Cache(true,true,false,true,"com.opensymphony.oscache.base.algorithm.UnlimitedCache",Integer.MAX_VALUE);
+ }
+
+ public static CacheManager getInstance(Configuration conf){
+ CacheManager cache=(CacheManager)conf.getObject(CACHE_KEY);
+
+ if(cache==null) {
+ cache = new CacheManager();
+
+ conf.setObject(CACHE_KEY, cache);
+ }
+ return cache;
+ }
+
+ /**
+ * Get Search object from cache
+ * @param id key
+ * @return
+ * @throws NeedsRefreshException
+ */
+ public Search getSearch(String id) throws NeedsRefreshException {
+ return (Search) cache.getFromCache(id);
+ }
+
+ /**
+ * Put Search object in cache
+ *
+ * @param id key
+ * @param search the search to cache
+ */
+ public void putSearch(String id, Search search){
+ cache.putInCache(id,search,policy);
+ }
+
+}
Added: lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/controller/CachingSearchController.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/controller/CachingSearchController.java?rev=409869&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/controller/CachingSearchController.java (added)
+++ lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org/apache/nutch/webapp/controller/CachingSearchController.java Sat May 27 13:36:55 2006
@@ -0,0 +1,56 @@
+package org.apache.nutch.webapp.controller;
+
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.nutch.webapp.CacheManager;
+import org.apache.nutch.webapp.common.Search;
+import org.apache.nutch.webapp.common.ServiceLocator;
+import org.apache.struts.tiles.ComponentContext;
+
+import com.opensymphony.oscache.base.NeedsRefreshException;
+
+/**
+ * This naive search result caching implementation is just an example of
+ * extending the web ui.
+ */
+public class CachingSearchController extends SearchController {
+
+ public void nutchPerform(ComponentContext tileContext,
+ HttpServletRequest request, HttpServletResponse response,
+ ServletContext servletContext) throws ServletException, IOException {
+
+ Search search = null;
+ boolean requiresUpdate = false;
+
+ // key used for caching
+ String key = request.getQueryString();
+
+ ServiceLocator locator = getServiceLocator(request);
+
+ try {
+ search = CacheManager.getInstance(locator.getConfiguration()).getSearch(
+ key);
+ request.setAttribute("resultInfo", search.getResultInfo());
+ request.setAttribute("nutchSearch", search);
+
+ LOG.fine("Using cached");
+ } catch (NeedsRefreshException e) {
+ requiresUpdate = true;
+ LOG.fine("Cache update required");
+ }
+
+ if (search == null || requiresUpdate) {
+ LOG.fine("Cache miss");
+ super.nutchPerform(tileContext, request, response, servletContext);
+ search = (Search) request.getAttribute(SearchController.REQ_ATTR_SEARCH);
+ CacheManager.getInstance(locator.getConfiguration()).putSearch(key,
+ search);
+ }
+
+ }
+}
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Nutch-cvs mailing list
Nutch-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nutch-cvs
Re: [Nutch-cvs] svn commit: r409869 - in /lucene/nutch/trunk/contrib/web2/plugins/caching-oscache/src/java/org:
./ apache/ apache/nutch/ apache/nutch/webapp/ apache/nutch/webapp/controller/
Posted by Sami Siren <ss...@gmail.com>.
ogjunk-nutch@yahoo.com wrote:
>Spotted a reference to "NutchReferehPolicy();" :
> EntryRefreshPolicy policy=new NutchReferehPolicy();
>
>Typo?
>
>
Yes it was, thanks for keeping your eyes open.
--
Sami Siren
>Otis
>
>