[
http://jira.jboss.com/jira/browse/JBSEAM-1891?page=all ]
Christian Bauer updated JBSEAM-1891:
------------------------------------
Priority: Major (was: Critical)
I can downgrade this now, I managed to hack my own page fragment cache by cloning
CacheRenderBase and accessing my own "pojocache".
If we want to remove the dependency on jboss cache in the core, we also need to write an
abstract cache put/get/remove API first. For the record, here is my implementation:
/**
* Implementation of <tt><s:cache></tt> renderer based on
EHCache.
*
* @author Christian Bauer
*/
public class WikiPageFragmentCacheRenderer extends RendererBase {
private static final LogProvider log = Logging.getLogProvider(UICache.class);
@Override
protected Class getComponentClass() {
return UICache.class;
}
@Override
protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
UICache cache = (UICache) component;
if (cache.isEnabled()) {
String key = cache.getKey();
String cachedContent = getFromCache(key);
if (cachedContent == null) {
log.debug("rendering from scratch: " + key);
StringWriter stringWriter = new StringWriter();
ResponseWriter cachingResponseWriter =
writer.cloneWithWriter(stringWriter);
context.setResponseWriter(cachingResponseWriter);
renderChildren(context, component);
context.setResponseWriter(writer);
String output = stringWriter.getBuffer().toString();
writer.write(output);
putInCache(key, output);
} else {
log.debug("rendering from cache: " + key);
writer.write("<!-- cached content for: ");
writer.write(key);
writer.write(" -->");
writer.write(cachedContent);
writer.write("<!-- end of cached content -->");
}
} else {
log.debug("cached rendering is disabled for: " + cache.getKey());
renderChildren(context, component);
}
}
@Override
public boolean getRendersChildren() {
return true;
}
public static void putInCache(String key, String content) {
WikiPageFragmentCache.instance().put(key, content);
}
public static String getFromCache(String key) {
return WikiPageFragmentCache.instance().get(key);
}
}
@Name("wikiPageFragmentCache")
@Scope(ScopeType.APPLICATION)
@BypassInterceptors
public class WikiPageFragmentCache {
private static final LogProvider log =
Logging.getLogProvider(WikiPageFragmentCache.class);
public static final String CACHE_REGION_NAME = "WikiPageFragmentCache";
Cache cache;
@Create
public void start() throws Exception {
log.info("obtaining Hibernate cache provider from JNDI to build wiki page
fragment cache region");
try {
CacheManager manager = EHCacheManager.instance();
cache = EHCacheManager.instance().getCache(CACHE_REGION_NAME);
if (cache == null) {
log.warn("Could not find configuration [" + CACHE_REGION_NAME +
"]; using defaults.");
manager.addCache(CACHE_REGION_NAME);
cache = manager.getCache(CACHE_REGION_NAME);
log.debug("started EHCache region: " + CACHE_REGION_NAME);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public void put(String key, String content) {
cache.put(new Element(key, content));
}
public String get(String key) {
Element result = cache.get(key);
return result != null ? (String)result.getValue() : null;
}
public void remove(String key) {
cache.remove(key);
}
public static WikiPageFragmentCache instance() {
if (!Contexts.isApplicationContextActive()) {
throw new IllegalStateException("No active application scope");
}
return (WikiPageFragmentCache) Component.getInstance(WikiPageFragmentCache.class,
ScopeType.APPLICATION);
}
}
<!-- Custom renderer implementation for s:cache page fragment caching -->
<render-kit>
<render-kit-id>HTML_BASIC</render-kit-id>
<renderer>
<component-family>org.jboss.seam.ui.Cache</component-family>
<renderer-type>
org.jboss.seam.ui.CacheRenderer
</renderer-type>
<renderer-class>
org.jboss.seam.wiki.core.ui.WikiPageFragmentCacheRenderer
</renderer-class>
</renderer>
</render-kit>
Note that my implementation does not support regions, it's all in one region.
Decouple page fragment caching from JBoss Cache
-----------------------------------------------
Key: JBSEAM-1891
URL:
http://jira.jboss.com/jira/browse/JBSEAM-1891
Project: JBoss Seam
Issue Type: Task
Components: Core, JSF Controls
Reporter: Christian Bauer
Fix For: 2.1.0.GA
The code in UICache and PojoCache only works with this component:
return (org.jboss.cache.aop.PojoCache) Component.getInstance(PojoCache.class,
ScopeType.APPLICATION);
Make this generic so that other cache providers can be used.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira