=================================== Caching for GNUJSP 0.9.10 jsp pages Robert Chou v2 rob_chou@bigfoot.com =================================== Changes: -------- - <%@ include virtual="somefile" %> can now use a relative path - merged Paul Siegmann's "Parsing of tags" patch - apache/jserv group has acknowledge bug with If-Modified- Since header in 1.3.6. It should fixed in a future release. See "Issues" section below for details. - minor bug fix =================================== Caching for GNUJSP 0.9.10 jsp pages Robert Chou v1 rob_chou@bigfoot.com =================================== Why? ---- I implement a lot of jsp pages simply to take advantage of substitions for things like email addresses, version numbers, etc. I change these values infrequently, but when I do, they get propagated through my entire site. This works great, but performance is slow. It doesn't return a content length and can't use keep alives. It also can't use the last modified dates for conditional gets and heads. So, for those pages which do not let users query database tables for results, I added the ability for GNUJSP to cache jsp's output. I called this the "cache_simple_html" directive. How to use it ------------- >From here on, when I refer to GNUJSP, I refer to my modified version. By default, the new caching functionality is turned off for ALL jsp pages. To enable this new behavior, you must first set the following servlet property: cache_simple_html=true For example, my zone.properties has this line: servlet.gnujsp.initArgs=repository=c: \apps\jserv\gnujsp\generatedClassfiles,cache_simple_html=tru e Next, you need to add a directive to every jsp file which you want to cache. For example, if you wanted to cache /htdocs/main.jsp (which simply had substitutions for your most current email address), add the following line at the beginning of the file: <%@ cache_simple_html="true" %> ... ...<%= bSomeBean.show_email_somehow() %>... ... Now, bring up this page in your browser and the page will show, after jsp compilation, as usual. However, hit it again with telnet and you'll see that it's now returning a last modified date, along with a content length! (see Issues at end of readme for info about apache/jserv bug). If you take a look at your /htdocs directory, you should now see a main.jsp.*.html along with your main.jsp file. (see How it works section below for eplanation of the "*"). If you want to refresh this file, you can either edit main.jsp, or delete this cache file. Advanced options: ----------------- Ok, so you've got most of you jsp's cached now, and you change your email address. What now? 1. You can either touch all the jsp files, 2. or you can use a script to delete all the cache files (see how it works section on how to uniquely identify cache html files). 3. delete the .class files in your generatedClassfiles directory. 4. set a "cache_recycle_millis" directive! The following directive in a jsp file will recycle the cache every 10 seconds: <%@ cache_recycle_millis="10000" %> The following directive in a jsp file will also recycle the cache every 10 seconds: <%@ cache_recycle_millis="s10" %> The following directive in a jsp file will recycle the cache every 10 minutes: <%@ cache_recycle_millis="m10" %> The valid prefixes are: s=seconds m=minutes h=hours d=days w=weeks (7 days) How it works ------------ Caching only works with GET and HEAD requests. The caching directives will be ignored for PUT, POST, etc. You can even GET/POST to the same jsp with cache enabled, with no ill effects. QueryStrings for GETs are supported, but you should only cache jsp pages where are not allowing the user to selectively query from a database table. Otherwise, the cache files may get numerous. Different character encodings are supported also. Basically, here's a sample mapping from jsp file to cache file names. GET /main.jsp?test=abc HTTP/1.0 If caching is enabled, and main.jsp has the caching directive, and main.jsp resides /htdocs. The cache file will also reside in /htdocs, under the name: main.jsp.test%3Dabc.ISO-8859-1.html The querystring and character encoding is embedded inside the cache file name. You should be able to uniquely identify jsp cache files with the mask "*.jsp.*.html". Issues: ------- Q> If you return the last modfied date, then why does a conditional get not return a 304 on cache files that have not changed? A> This seems to be a bug somewhere in Apache/JServ. I've contacted the apache mailing list for help. The header "If-Modified-Since" is always null to servlets in Apache 1.3.6./JServ 1.0b5. _______________________________________________________ Get Visto! Groups, event calendars, email, and more... Check it out @ http://www.visto.com/info