BEA Systems, Inc.

com.beasys.commerce.content
Class ContentCache

java.lang.Object
  |
  +--com.beasys.commerce.content.ContentCache

public class ContentCache
extends java.lang.Object
implements javax.servlet.http.HttpSessionBindingListener, java.io.Serializable

A little cache bean for caching content.

This object is generally placed in an HttpSession (via the bindToSession() and getFromSession() methods).

Internally, this obeys the ContentHelper.USE_SOFT_HASH_MAP parameter. If that's false, then a regular HashMap will be used to cache the Content. In this case, caching should be used judiciously and always with a max and timeout. If ContentHelper.USE_SOFT_HASH_MAP is true, than a SoftHashMap will be used. This will allow the garbage collector to collect cached data as memory requirements change and will prevent the ContentCaches from causing OutOfMemoryErrors. However, under the Solaris Production VM (1.2.1_04), SoftReferences (and WeakReferences) are almost immediately collected, thereby nullifying any performance bonus from using the ContentCache.

Since:
2.0.1 sp1
See Also:
Serialized Form

Field Summary
static java.lang.String SESSION_NAME
          The name of the ContentCache in the HttpSession ("wlcs.content.cache").
 
Constructor Summary
ContentCache()
          Constructor.
 
Method Summary
static void bindToSession(ContentCache cache, javax.servlet.http.HttpSession session)
          Bind a ContentCache into an HttpSession.
 Content[] getContent(java.lang.String id, long timeout)
          Check the cache for the content.
static ContentCache getFromSession(javax.servlet.http.HttpSession session, boolean create)
          Get a ContentCache from an HttpSession.
 void update(java.lang.String id, Content[] content)
          Update the cache with the content.
 void valueBound(javax.servlet.http.HttpSessionBindingEvent evt)
          Called when we're bound into an HttpSession.
 void valueUnbound(javax.servlet.http.HttpSessionBindingEvent evt)
          Called when we're unbound from an HttpSession, and clears the cache.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_NAME

public static final java.lang.String SESSION_NAME
The name of the ContentCache in the HttpSession ("wlcs.content.cache").
Constructor Detail

ContentCache

public ContentCache()
Constructor.
Method Detail

getContent

public Content[] getContent(java.lang.String id,
                            long timeout)
Check the cache for the content.
Parameters:
id - the cache id of the content.
timeout - the timeout in ms. for the content (less than 0 for no timeout).
Returns:
the array of Content, or null if not found or has timed out.

update

public void update(java.lang.String id,
                   Content[] content)
Update the cache with the content.

This can be used for new or existing content in the cache.

Parameters:
the - cache id of the content.
content - the Content (null to remove).

valueBound

public void valueBound(javax.servlet.http.HttpSessionBindingEvent evt)
Called when we're bound into an HttpSession.
Specified by:
valueBound in interface javax.servlet.http.HttpSessionBindingListener

valueUnbound

public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent evt)
Called when we're unbound from an HttpSession, and clears the cache.
Specified by:
valueUnbound in interface javax.servlet.http.HttpSessionBindingListener

bindToSession

public static void bindToSession(ContentCache cache,
                                 javax.servlet.http.HttpSession session)
Bind a ContentCache into an HttpSession.

This will use SESSION_NAME as the session attribute name for the cache.

Parameters:
cache - the content cache object.
session - the http session.

getFromSession

public static ContentCache getFromSession(javax.servlet.http.HttpSession session,
                                          boolean create)
Get a ContentCache from an HttpSession.

This will retrieve the cache from the session attribute named SESSION_NAME. If that is set and is not a ContentCache, it will be removed.

Parameters:
session - the http session.
create - true to create a ContentCache if it's not there, false to not and return null.
Returns:
the cache if it exists or create was true, null if it didn't exist and create was false.

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved