Caching challenges

To ensure that we keep in mind the pattern we target when we put caching in place, let's use a simple example taken from our quote manager application. Our goal will be to make our find by symbol endpoint go faster. The current logic looks like this pseudo code snippet:

Quote quote = database.find(symbol);if (quote == null) {    throw NotFoundException();}return convertToJson(quote);

We only have two operations in this code snippet (find it in the database and convert the database model into a JSON model). Wonder what you're caching: the database lookup result, the JSON conversion, or both?

We will come back to this part later, but to keep it simple, here, we will just cache the database lookup. Therefore, our new pseudo code ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.