Book Image

Infinispan data grid platform definitive guide

Book Image

Infinispan data grid platform definitive guide

Overview of this book

Table of Contents (20 chapters)
Infinispan Data Grid Platform Definitive Guide
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing the cache-aside programming pattern


Perhaps the most common caching pattern in use today is cache-aside. In this strategy, an application populates a cache lazily, as applications request data, and as the system runs, the cache client gradually populates the cache to contain most of the data that it refers to frequently.

In this pattern, the cache doesn't interact with the database; it is kept aside as a more scalable in-memory data store.

Note

Infinispan will always attempt to load data from CacheStore or CacheLoader. We are talking about a situation where the data comes from an external data store, such as a database.

Consider a simple Reference Data Service example, which will be used to store and retrieve reference data, as the meaning of a given code. For instance, for the code M, the service will return Male for the meaning. A basic implementation is shown in the following listing:

public class ReferenceCodeService {
  private final Cache<String, String> cache;
  private...