• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Servlet question about caching a response  RSS feed

 
Paul Duer
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I know I should know how to do this, but well the drugs...

Anywho, I have a need to cache a small XML file in a servlet to send back as a HTTP response for consuming in a Flex HTTPService object.

The deal here is that the XML will be getting requested probably like 1000s of times a minute, to update the Flex Graph I am building.

The XML will be updated however every 30 seconds. The goal I have in mind is to keep the XML in memory and not read it from disk everytime it's requested. Then I want to be able to update the XML object every 30 seconds inside the servlet.

So what type of object will work best and what scope should it have?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the same XML will be served for all users and all requests, application scope is a good place to put it.

You can create a factory object that produces the XML. All servlets that need it would ask this object for it, and the object decides if its ok to serve a saved copy or if it's time to read a new one. That way, the rest of your app doesn't have to care about timing and caching.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!