JEE

Building your own self refreshing cache in Java EE

Posted on by  
Jeroen Resoort

If you have read my previous post about caching, The (non)sense of caching, and have not been discouraged by it, I invite you to build your own cache. In this post we will build a simple cache implementation that refreshes its data automatically, using Java EE features.

Let's describe the situation. We are building a service that uses an external resource with some reference data. The data is not frequently updated and it's allright to use data that's up to 1 hour old. The external resource is very slow, retrieving the data takes about 30 seconds. Our service needs to respond within 2 seconds. Obviously we can't call the resource each time we need it. To solve our problem we decide to introduce some caching. We are going to retrieve the entire dataset, keep it in memory and allow retrieval of specific cached values by their corresponding keys.

Continue reading →

shadow-left