10 Caching

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • Building your first caching application
  • Working with cache annotations
  • Implementing cache managers
  • Casting your SpEL on caches
  • Initializing your caches programmatically
  • Finding alternative cache providers

We can define cache as a storage mechanism that holds the data in one place to be served for future requests in a faster way. One of the common use cases of employing cache mechanisms in an application is avoiding multiple executions of the methods to overcome the performance drawbacks. You can achieve this by caching the outcome data of methods according to the input values given. Of course, you can apply this process to deterministic methods that produce the same output every time, for the exact input given regardless of the numerous executions. If any of the methods contain any implementation of a random calculation computing, for instance, caching will lead to drastic problems, and caching these randomized methods should be avoided.

To boost performance in the enterprise applications, Spring also provides a caching abstraction that offers method-level caching. By employing aspect-oriented programming (AOP) principles, methods are weaved, and if they have already been executed ...

Get Beginning Spring 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.