Search

22.2. Page fragment caching

download PDF
The <s:cache> tag is Seam's solution to the problem of page fragment caching in JSF. <s:cache> uses pojoCache internally, so you will need to follow the previous steps — place the JARs in the EAR and edit additional configuration options — before you can use it.
<s:cache> stores some rendered content that is rarely updated. For example, the welcome page of our blog displays recent blog entries:
<s:cache key="recentEntries-#{blog.id}" region="welcomePageFragments"> 
  <h:dataTable value="#{blog.recentEntries}" var="blogEntry"> 
    <h:column> 
      <h3>#{blogEntry.title}</h3> 
      <div> 
        <s:formattedText value="#{blogEntry.body}"/> 
      </div> 
    </h:column> 
  </h:dataTable> 
</s:cache>
The key lets you store multiple versions of each page fragment. In this case, there is one cached version per blog. The region determines the cache or region node where all versions are stored. Different nodes may have differing expiry policies.
The <s:cache> cannot tell when the underlying data is updated, so you will need to manually remove the cached fragment when a change occurs:
public void post() { 
  ... 
  entityManager.persist(blogEntry); 
  cacheProvider.remove("welcomePageFragments", 
                       "recentEntries-" + blog.getId()); 
}
If changes need not be immediately visible to the user, you can set up a short expiry period on the cache node.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.