[Opensymphony-oscache] Working with oscache
Francisco Jose Garcia Garcia <[email protected]> Fri, 27 May 2005 01:27:13 CDT
| Newsgroups | gmane.comp.java.open-symphony.os-cache |
|---|---|
| Message-ID | <25544041.1117175734202.JavaMail.os-j2ee@opensymphony01.contegix.com> |
[b]To regenerate the cache we do that:[/b]
String dirname = "/usr/local/oscache/application";
long timeIni = System.currentTimeMillis();
File f1 = new File(dirname);
if (f1.isDirectory()) {
out.println("Directorio de " + dirname +"<br>");
String s[] = f1.list();
for (int i = 0; i < s.length; i++) {
File f2 = new File(dirname+"/"+s[i]);
if (f2.isDirectory()) {
continue;
}
else {
try{
FileInputStream fis = new FileInputStream(f2);
ObjectInputStream ois = new ObjectInputStream(fis);
CacheEntry entrada = (CacheEntry) ois.readObject();
ois.close();
if(entrada.getURL()==null)
continue;
out.println("Limpiando "+entrada.getURL()+"... ");
out.flush();
String pagina = entrada.getURL().replaceAll("&","%26");
URL server = new URL("http://foohost/deleteCache.jsp?URL=http://foohost/"+pagina);
HttpURLConnection connection = (HttpURLConnection)server.openConnection();
connection.connect();
if(connection.getResponseCode()==200)
{
out.println("<b>[OK]</b>"+"<br>");
}
else
{
out.println("<b>[ERROR]</b>"+"<br>");
}
}
catch(java.io.InvalidClassException e)
{
}
catch(Exception ex){
out.println(ex+"<br>");
continue;
}
}
}
} else {
out.println(dirname + " no es un directorio");
}
long timeFIN = System.currentTimeMillis();
double tiempo=0.0;
tiempo = (timeFIN-timeIni)/1000.0;
out.println("Tiempo invertido: <b>"+tiempo+"</b> segundos<br>");
[b]We call a page named deleteCache which has this code.[/b]
ServletCacheAdministrator admin = (ServletCacheAdministrator)
application.getAttribute("__oscache_admin");
String myKey = request.getParameter("URL");
myKey=generateKey(myKey);
Cache mycache = admin.getAppScopeCache(application);
mycache.flushEntry(admin.generateEntryKey(myKey,request,PageContext.APPLICATION_SCOPE));
out.println(urlOriginal);
response.sendRedirect(urlOriginal);
}
else
{
throw new Exception("Falta el parametro URL asociado");
}
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=2634&messageID=7357#7357