changes in skin caching: the response object now holds a local
skin cache which is expunged each time the skin path is set. But no more long term skin caching in the application or skin manager.
This commit is contained in:
parent
15cc95f9e1
commit
d1a36dc7e0
2 changed files with 29 additions and 11 deletions
|
@ -5,6 +5,7 @@ package helma.framework;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import helma.framework.core.Skin;
|
||||||
import helma.objectmodel.*;
|
import helma.objectmodel.*;
|
||||||
import helma.util.*;
|
import helma.util.*;
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ import helma.util.*;
|
||||||
* class are directly exposed to JavaScript as global property res.
|
* class are directly exposed to JavaScript as global property res.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ResponseTrans implements Externalizable {
|
public final class ResponseTrans implements Externalizable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the MIME content type of the response.
|
* Set the MIME content type of the response.
|
||||||
|
@ -64,6 +65,8 @@ public class ResponseTrans implements Externalizable {
|
||||||
private transient Object skinpath = null;
|
private transient Object skinpath = null;
|
||||||
// the processed skinpath as array of Nodes or directory names
|
// the processed skinpath as array of Nodes or directory names
|
||||||
private transient Object[] translatedSkinpath = null;
|
private transient Object[] translatedSkinpath = null;
|
||||||
|
// hashmap for skin caching
|
||||||
|
private transient HashMap skincache;
|
||||||
|
|
||||||
static final long serialVersionUID = -8627370766119740844L;
|
static final long serialVersionUID = -8627370766119740844L;
|
||||||
|
|
||||||
|
@ -327,8 +330,9 @@ public class ResponseTrans implements Externalizable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSkinpath (Object obj) {
|
public void setSkinpath (Object obj) {
|
||||||
this.skinpath = obj;
|
skinpath = obj;
|
||||||
this.translatedSkinpath = null;
|
translatedSkinpath = null;
|
||||||
|
skincache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getSkinpath () {
|
public Object getSkinpath () {
|
||||||
|
@ -343,6 +347,18 @@ public class ResponseTrans implements Externalizable {
|
||||||
return translatedSkinpath;
|
return translatedSkinpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Skin getCachedSkin (String id) {
|
||||||
|
if (skincache == null)
|
||||||
|
return null;
|
||||||
|
return (Skin) skincache.get (id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cacheSkin (String id, Skin skin) {
|
||||||
|
if (skincache == null)
|
||||||
|
skincache = new HashMap ();
|
||||||
|
skincache.put (id, skin);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void setCookie (String key, String value) {
|
public synchronized void setCookie (String key, String value) {
|
||||||
setCookie (key, value, -1);
|
setCookie (key, value, -1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.xml.sax.InputSource;
|
||||||
* (Node objects), the global prototype, the session object etc.
|
* (Node objects), the global prototype, the session object etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class HopExtension {
|
public final class HopExtension {
|
||||||
|
|
||||||
protected Application app;
|
protected Application app;
|
||||||
protected FesiEvaluator fesi;
|
protected FesiEvaluator fesi;
|
||||||
|
@ -436,11 +436,7 @@ public class HopExtension {
|
||||||
if (arguments.length != 1 || ESNull.theNull.equals (arguments[0]))
|
if (arguments.length != 1 || ESNull.theNull.equals (arguments[0]))
|
||||||
throw new EcmaScriptException ("createSkin must be called with one String argument");
|
throw new EcmaScriptException ("createSkin must be called with one String argument");
|
||||||
String str = arguments[0].toString ();
|
String str = arguments[0].toString ();
|
||||||
Skin skin = (Skin) app.skincache.get (str);
|
Skin skin = new Skin (str, app);
|
||||||
if (skin == null) {
|
|
||||||
skin = new Skin (str, app);
|
|
||||||
app.skincache.put (str, skin);
|
|
||||||
}
|
|
||||||
return new ESWrapper (skin, evaluator);
|
return new ESWrapper (skin, evaluator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,8 +498,14 @@ public class HopExtension {
|
||||||
|
|
||||||
// ready... retrieve the skin and render it.
|
// ready... retrieve the skin and render it.
|
||||||
Object javaObject = thisObject == null ? null : thisObject.toJavaObject ();
|
Object javaObject = thisObject == null ? null : thisObject.toJavaObject ();
|
||||||
if (skin == null)
|
if (skin == null) {
|
||||||
skin = app.getSkin (javaObject, arguments[0].toString (), skinpath);
|
String skinid = app.getPrototypeName(javaObject)+"/"+arguments[0].toString ();
|
||||||
|
skin = res.getCachedSkin (skinid);
|
||||||
|
if (skin == null) {
|
||||||
|
skin = app.getSkin (javaObject, arguments[0].toString (), skinpath);
|
||||||
|
res.cacheSkin (skinid, skin);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (asString)
|
if (asString)
|
||||||
res.pushStringBuffer ();
|
res.pushStringBuffer ();
|
||||||
if (skin != null)
|
if (skin != null)
|
||||||
|
|
Loading…
Add table
Reference in a new issue