Announcement Announcement Module
No announcement yet.
Caching HTML Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Caching HTML

    Hello all -

    Is there anyway to cache the resulting HTML of a request? Similar to what Django does with their framework.

    -- i apologize for the cross post, but I just realized that I posted in the wrong forum.


  • #2
    If what you want to do is cache the entire response, I'd go for something like squid ( rather than do something within the application.
    If you're not that worried about up-to-dateness, just add an 'Exipires' header a few minutes/hours (adjust to fit requirements) into the future on the reponse, and put a squid in front of your app server. You'll need to know a little about HTTP to ensure that your requests are actually cacheable.

    For cacheing JSP fragments, OSCache seems to be fairly well thought of, but I find it's generally simpler to cache the object graph and re-render it for each request than to try and cache the output of individual JSP / Tiles / Tags . I've not yet seen an app where JSP rendering was that much of a bottleneck.

    Incidentally if you've got a big (multi-GB) cache you probably don't want it in the JVM's heap as you'll need to spend a long time tuning your garbage collector. I'd suggest using something like memcached to hold the actual data.


    • #3
      Thanks for the reply. We haven't thought much about the mem requirements of caching yet, we're still trying to see if caching is possible -- in particular caching the fragments of a JSP page.

      How would one go about caching rendered JSP fragments? Lets assume that a user has a header, navigation sidebar, and main content sections. Is it possible to cache the (already rendered) header and navigation sections and dynamically insert them into a page?

      Thanks in advance,


      • #4

        Something like this:

        <cache:cache time="1800" >
        ... some jsp content that's slow to render ...

        but as a general rule, I'd caution against doing this unless you know it's necessary. 9 times out of 10 if you enable cacheing at the entity layer (e.g. with hibernate, enable L2 cacheing, or with EJB use commit option 'A') you won't need this, and you'll have more accurate data being sent back to your users.

        Profile twice, optimise once :-) !