|
BEA Systems, Inc. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.beasys.commerce.content.ContentCache
A little cache bean for caching content.
This object can placed anywhere for use as a cache. For convience, the
getContentCache
method can be used with a JSP
PageContext to create and utilize ContentCaches.
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.
Field Summary | |
protected java.util.Map |
cache
The cache of id to ContentHolder. |
static java.lang.String |
DEF_CACHE_NAME
The default name of the ContentCache in the various locations ("wlcs.content.cache"). |
static java.lang.String |
SESSION_NAME
Deprecated. Use DEF_CACHE_NAME instead. |
Constructor Summary | |
ContentCache()
Constructor. |
Method Summary | |
static void |
bindToSession(ContentCache cache,
javax.servlet.http.HttpSession session)
Bind a ContentCache into an HttpSession. |
void |
clear()
Clear the entire cache. |
static java.lang.Object |
getAttribute(javax.servlet.jsp.PageContext ctx,
java.lang.String name,
int scope)
Get a scoped attribute correctly from the JSP page context. |
long |
getCachedTime(java.lang.String id)
Get the UTC time (in ms.) of when the Content at id was cached. |
java.util.List |
getCacheIds()
Get an unordered list of all the cache ids. |
long |
getCacheSize()
Get the total number of Content objects cached (across all ids). |
Content[] |
getContent(java.lang.String id,
long timeout)
Check the cache for the content. |
static ContentCache |
getContentCache(javax.servlet.jsp.PageContext ctx,
int scope,
boolean create)
Get a ContentCache from the specified JSP context. |
static ContentCache |
getContentCache(javax.servlet.jsp.PageContext ctx,
java.lang.String scopeStr,
boolean create)
Get a ContentCache from the specified JSP context. |
static ContentCache |
getFromSession(javax.servlet.http.HttpSession session,
boolean create)
Get a ContentCache from an HttpSession. |
int |
getNumCacheIds()
Get the number of cache ids in the cache. |
static java.lang.String |
getScopeName(int scope)
|
Content[] |
remove(java.lang.String id)
Clear a particular entry from the cache. |
static void |
removeAttribute(javax.servlet.jsp.PageContext ctx,
java.lang.String name,
int scope)
Remove a scoped attribute correctly from the JSP page context. |
static void |
setAttribute(javax.servlet.jsp.PageContext ctx,
java.lang.String name,
java.lang.Object val,
int scope)
Set a scoped attribute correctly in the JSP page context. |
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 |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final java.lang.String DEF_CACHE_NAME
When the getContentCache
method is used,
this is the name which will used.
public static final java.lang.String SESSION_NAME
This is set to DEF_CACHE_NAME
.
protected java.util.Map cache
Constructor Detail |
public ContentCache()
Method Detail |
public Content[] getContent(java.lang.String id, long timeout)
Getting content from the cache does not update it's time in terms of
a timeout. Only using the update(java.lang.String, com.beasys.commerce.axiom.content.Content[])
method to update the cache
will do that.
id
- the cache id of the content.timeout
- the timeout in ms. for the content (less than 0 for no
timeout).public long getCachedTime(java.lang.String id)
id
- the cache id of the content.public int getNumCacheIds()
public java.util.List getCacheIds()
Since the keys will all be Strings, this can be sorted with
Collections.sort(java.util.List)
.
public long getCacheSize()
public void update(java.lang.String id, Content[] content)
This can be used for new or existing content in the cache.
id
- cache id of the content.content
- the Content (null to remove).public Content[] remove(java.lang.String id)
id
- the cache id of the content.public void clear()
public void valueBound(javax.servlet.http.HttpSessionBindingEvent evt)
public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent evt)
clear()
public static void bindToSession(ContentCache cache, javax.servlet.http.HttpSession session)
This will use DEF_CACHE_NAME
as the session
attribute name for the cache.
cache
- the content cache object.session
- the http session.public static ContentCache getFromSession(javax.servlet.http.HttpSession session, boolean create)
This will retrieve the cache from the session attribute named
DEF_CACHE_NAME
. If that is set and is not a
ContentCache, it will be removed.
session
- the http session.create
- true to create a ContentCache if it's not there, false to
not and return null.public static ContentCache getContentCache(javax.servlet.jsp.PageContext ctx, int scope, boolean create)
This will retrieve the ContentCache from the JSP context based upon
the specified scope at the attribute named
DEF_CACHE_NAME
. If that is set and is not a
ContentCache, it will be removed.
ctx
- the JSP page context.scope
- the cache scope (one of PageContext.APPLICATION_SCOPE,
PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE, or
PageContext.SESSION_SCOPE).create
- true to create a ContentCache if it's not there, false to
not and return null.public static ContentCache getContentCache(javax.servlet.jsp.PageContext ctx, java.lang.String scopeStr, boolean create)
If scopeStr is "application", then PageContext.APPLICATION_SCOPE is used; if scopeStr is "page", then PageContext.PAGE_SCOPE is used; if scopeStr is "request", then PageContext.REQUEST_SCOPE is used; if scopeStr is "session", then PageContext.SESSION_SCOPE is used; otherwise, scopeStr is passed to ctx.getAttributesScope() which will determine the scope to use.
ctx
- the JSP page context.scopeStr
- the scope name.create
- true to create a ContentCache if it's not there, false to
not and return null.public static java.lang.Object getAttribute(javax.servlet.jsp.PageContext ctx, java.lang.String name, int scope)
The scoped methods on the WLS PageContext throw NPEs, so this method does the equivalent.
ctx
- the JSP page context.name
- the attribute name.scope
- the attribute scope (PageContext.APPLICATION_SCOPE,
PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE,
PageContext.SESSION_SCOPE).public static void setAttribute(javax.servlet.jsp.PageContext ctx, java.lang.String name, java.lang.Object val, int scope)
The scoped methods on the WLS PageContext throw NPEs, so this method does the equivalent.
ctx
- the JSP page context.name
- the attribute name.val
- the attribute value.scope
- the attribute scope (PageContext.APPLICATION_SCOPE,
PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE,
PageContext.SESSION_SCOPE).public static void removeAttribute(javax.servlet.jsp.PageContext ctx, java.lang.String name, int scope)
The scoped methods on the WLS PageContext throw NPEs, so this method does the equivalent.
ctx
- the JSP page context.name
- the attribute name.scope
- the attribute scope (PageContext.APPLICATION_SCOPE,
PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE,
PageContext.SESSION_SCOPE).public static java.lang.String getScopeName(int scope)
|
BEA Systems, Inc. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |