You can create your own provider class which can be a singleton and can
be injected on your resources.
See
http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/spi/inject/SingletonTypeInjectableProvider.html
Something like:
@Provider
public class MyCacheProvider extends
SingletonTypeInjectableProvider<Context, MyCache> {
public MyCacheProvider() {
super(MyCache.class, new MyCache());
}
}
Then in your resources you can do:
@Context MyCache cache;
@GET
public String get() {
return cache.getCachedItem();
}
Hope you get the idea.
Martin
On 9.3.2011 18:15, Arthur Yeo wrote:
> Martin,
>
> May be I should ask if there is "global" place in Jersey where I can
> store something that's accessible by all RESTful services answering to
> incoming requests?
>
>
> On Wed, Mar 2, 2011 at 11:52 AM, Arthur Yeo <artyyeo_at_gmail.com
> <mailto:artyyeo_at_gmail.com>> wrote:
>
> Hi Martin,
>
> Jersey is beautiful and I love it.
>
> Since RESTful services are event-driven, what's the best practices
> to cache a bunch of static data (mainly configs stuffs) from the
> Db when my GF webapp *initially starts up*?
> I ask this because this operation is not exactly an HTTP event to
> response to incoming requests --- it's an internal startup op. How
> do you kick off something with no external events driving it?
>
> --
> Arthur Y.
>
>
>
>
> --
> Arthur Y.