Women in Technology

Hear us Roar

  Two Servlet Filters Every Web Application Should Have
Subject:   MIME types and Servlets that generate binary data
Date:   2003-12-12 15:07:35
From:   jfalkner
Response to: MIME types and Servlets that generate binary data

I was wondering how we could cache pages that use cookies or sessions. Any ideas anyone?

Could you clarify? What about the cookies or session would you want to use for either identifying cached information or for storing in the cache?

You can always cache more than just the content returned by a response. You could have a filter save multiple files in your cache, say one for content, one for session information, etc. However, you will have to have a creative method for figuring out what cache information to use. Perhaps something along the lines of loading user-specific cache information when they log in, or by detecting a cookie you've saved on their machine.

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • MIME types and Servlets that generate binary data
    2003-12-15 09:02:11  anonymous2 [View]

    For example, say that part of a web app displays a calendar whose events are particular to the user and whose month is particular to some session variable. If one wanted to use a caching filter to reduce the time of calendar generation, it seems that the filter would have to dig through session variables to determine what user is logged in and what month they have chosen. This is not difficult, but when one has a customized situation like this, it seems that the CacheFilter will have to be customized as well. I'm interested in knowing if there is a way to do this in a more generic way - namely, so that a caching filter can be used in such a situation without having to tailor it so that it works *only* in this situation.
    • MIME types and Servlets that generate binary data
      2004-01-07 18:52:12  jfalkner [View]

      Sure, you could solve this problem a few ways. One way is to cache based on URL parameters (which I think this filter does...) and simply put the information you care about in the URL.

      Another way would be to add another level of abstraction to the cache filter, e.g. allow cache-control objects to be registered to the filter, then have the filter both check the URL/headers/etc and the registered cache-control objects. It would then be up to you to code cache-control objects (say one for your calendar) and register them with the filter.