The cache key

Most cache APIs are very close to a map in terms of their behavior—you can put some data with put(key, value) and retrieve it back with the same key through a get(key) invocation.

This means that a poor man's cache can be implemented with ConcurrentMap of the JRE:

private final ConcurrentMap<Long, Optional<Quote>> quoteCache = new ConcurrentHashMap<>();@GET@Path("{id}")public JsonQuote findById(@PathParam("id") final long id) {    return quoteCache.computeIfAbsent(id, identifier ->     quoteService.findById(identifier))            .map(this::convertQuote)            .orElseThrow(() -> new WebApplicationException(Response.Status.NO_CONTENT));}

In this implementation, we wrapped the database access in a concurrent map access, which triggers the database ...

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.