You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Denes Pal <de...@mester.nir.hu> on 2003/01/15 12:59:15 UTC

caching content in portlets

Hi!

I have some problems understanding how portlets are instantiated or
reused and how threading issues are handled.

For example: can I safely use instance variables in my portlet to
cache some data between requests? What's the relation between a 
PortletInstance (as identified by a portlet id) and an instance of my 
portlet class? Will my instance be reused to serve different 
PortletInstances of the same class? Or will there be several instances of 
my class serving the same PortletInstance (to handle concurrent requests)?

Basically I would like to do something like this:

public class MyPortlet extends AbstractPortlet {
    private ConcreteElement content = null;
    
    public void init() {
	// cache the content in an instance variable
	content = createContentByExpensiveTransformation();
    }

    public ConcreteElement getContent(RunData runData) {
	// returned the previously constructed content
	return content;
    }
}

Or maybe this, trying to reuse some data between inits:

public class MyPortlet extends AbstractPortlet {
    private MyData data = null;
    private ConcreteElement content = null;
    
    public void init() {
	if (data == null) {  // called for the first time
	    data = getMyUnderlyingData();
	    content = createContentByExpensiveTransformation(data);
	}
	// called again, check if we can reuse our content
	else if (data.isExpired()) {
	    data.reloadMyUnderlyingData();
	    content = createContentByExpensiveTransformation(data);
	}
        // if everything is current, reuse it
    }

    public ConcreteElement getContent(RunData runData) {
	return content;
    }

}

Any ideas?

thanks,
denespal


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>