Data Types For Caching
Data Types For Caching
One of the big problems I see
when I talk with people about
caching is not recognizing the
different cached data types.
Understanding the different types
of data can help us to define
what sort of caching do we need and also how to use caching systems
to achieve the appropriate cache scenario we are going to use.
This post will describe how to define data types for caching.
Reference Data
Reference data is data that doesn’t change frequently. This kind of
data is usually a result of data storage/storages query or aggregate query.
Since it doesn’t change frequently it is very ideal for caching. Instead of
hitting the data source when we need this kind of data, in the first hit
we will store it in cache and then retrieve it from cache when it is needed.
Reference data can also change so we need to refresh it periodically.
A very good example of reference data can be catalogs or lookup tables
(for example countries lookup table) that don’t change frequently.
Activity-Oriented Data
Activity-oriented data as it’s name indicate is data that belong to some
business activity or transaction. The data is created inside a business
activity and then at the end of the activity is persisted into the data
storage for historical or log information. Such data type is a data per
open session. A good example for an activity data is shopping cart in
a web store like Amazon. Other examples can be a user session state
or purchase order. As you can understand this kind of data has exclusive
access and therefore it is very recommended to cache it.
Resource-Oriented Data
Resource-oriented data is shared, concurrently read and write into, and is
accessed by many users/transactions. This kind of data is very hard to keep
inside a cache since there can be race conditions between transactions and
many transactions can manipulate the data at the same time.If this kind of
data is used inside cache it should be handled with caution and you should
use concurrency mechanisms in order to minimize problems. Examples for
such data can be auction items and flight inventory.
Summary
Let sum up, it is very important to understand the kinds of data that you
are going to use with cache. Every data kind has it’s appropriate caching
scenarios and have different considerations. These data type include
reference data, activity-oriented data and resource-oriented data.