[jbossseam-issues] [JBoss JIRA] Updated: (JBSEAM-1891) Decouple page fragment caching from JBoss Cache

Christian Bauer (JIRA) jira-events at lists.jboss.org
Fri Mar 7 06:45:00 EST 2008

     [ 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>&lt;s:cache&gt;</tt> renderer based on EHCache.
 * @author Christian Bauer
public class WikiPageFragmentCacheRenderer extends RendererBase {

    private static final LogProvider log = Logging.getLogProvider(UICache.class);

    protected Class getComponentClass() {
        return UICache.class;

    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);
                renderChildren(context, component);
                String output = stringWriter.getBuffer().toString();
                putInCache(key, output);
            } else {
                log.debug("rendering from cache: " + key);
                writer.write("<!-- cached content for: ");
                writer.write(" -->");
                writer.write("<!-- end of cached content -->");
        } else {
            log.debug("cached rendering is disabled for: " + cache.getKey());
            renderChildren(context, component);

    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);


public class WikiPageFragmentCache {

    private static final LogProvider log = Logging.getLogProvider(WikiPageFragmentCache.class);

    public static final String CACHE_REGION_NAME = "WikiPageFragmentCache";

    Cache cache;

    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.");
                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) {

    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 -->

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


More information about the seam-issues mailing list