codesoju
Search…
Data Cache

What is Data Cache?

Data Cache is a hardware or software component that stores data so future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation, or the duplicate of data stored elsewhere.

Why to use Data Cache?

There are multiple reasons why to use Data Cache. One would be an efficiency in both resources and time.
Any developer would say 'Do not make an API call if you do not have to'. Any call takes time and it may result in errors due to a variety of reasons. Like in anything else the longer your process is the more chain elements are connected the bigger is the probability of an error. Sometimes it is unavoidable, but when we can avoid it we have to take advantage of it. Often if multiple users preform same type of operations with the application there is a portion of data that is shared. Every developer has to take advantage of it and make reusable blocks to improve the perfomance and to make the app faster and more stable.

Typical usage examples

  • Application content cache
  • Results of expensive calculations cache
  • Requests to databases cache

Data Cache in Codesoju based applications

In Codesoju based applications we would recommend using Data Cache for the content received from your Content Management System (CMS). Read more about CMS here. If your application has content coming from the CMS and it is used by, say, a million of users you wouldn't want to make a million of API calls to retrieve your content individually for each user.
Instead, you might consider the following scenario. The content could be received by the backend, processed by a processing engine and cached. It could be served to your users from the cache and you could configure your cache to be updated with some regularity based on your needs. It would be faster, more smooth, possibly less expensive and with fewer errors.
We would recommend using Redis for this purpose. It is easy to set it up and to start using it. It is simple in how it works. You store your data in Redis as a key-value pair. To retrieve it, use your key - unique identifier for the data set. It will check the cache. If the key is in the cache and it is not expired, then you get the value. The effort to set it up is definitely worth the benefits it will bring.