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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.