I have a Jersey (version 2) resource that, during request handling, creates an object that is used throughout the request.
I would like to cache this object in a thread local storage so that other request handlers that use the same thread could re-use this object.
Is this possible? How is this done in Jersey? I am totally new to Jersey and to Java in general, please help. Can I use javax.ws.rs.container.ContainerRequestContext
for this? How? How do I clear the cache?
EDIT:
Specific questions:
If I use
javax.ws.rs.container.ContainerRequestContext
to cache my objects, at what point can I clear the cache?Is clearing the cache necessary at all in this case?
Is it a good practice to use thread storage as a cache in servlets?