Spatial, Temporal, Distributed in backend server Caching

ishan vimukthi
3 min readJun 20, 2021
cache make slow things fast

What is caching?

Simply When we designing a backend server front-end clients can send requests to our server and get data as a response. But for the backend server cost of getting data Is high. The source of data may be another rest API or a database.
What cache does is store the frequently used data so that future requests for that data can be served faster.

What are the types of caching?

Spatial, Temporal, Distributed

  1. Spatial caching

spatial caching is simply getting the nearby data. For example, when we fixing a broken chair we don’t go for the toolbox for each item when we need it. But we predict all the tools that we need to fix a chair and bring them in one go.
Like that in spatial caching, we predict the future data that clients may request and cache them for giving a faster response.

2.Temporal caching

Temporal cache stores the most frequently used data for giving faster responses. For Example, if u visit a store you can see Pepsi or coke in coolers more often than other brands that’s because those drinks sold frequently than others.

Distributed cache

The distributed cache keeps our cache in sync with the main database so when data changes in the database or cache it automatically keeps both the ends in synch and we can distribute our cache through multiple nodes.

And for there are mainly 2 approaches.

1. Write-Through
first, write to the cache and then writes to the database immediately so we can ensure data is present in both the database and the cache this takes time because we need to write in 2 places.

2. Write-Back
write to the cache first. And then cache-store write back to the database asynchronously this is fast because we write data only to cache then asynchronously it will be updated in the database. This method is risky because what happens if this cache gets destroyed? Then we going to lose the data because it’s not written to the database.

--

--