0

Caching in programming

In what way we cache the data when we code? I mean do we use variables or any other thing to cache the dataset? Any example tagged with the solution would by great :)

7th Sep 2019, 12:37 PM
Ashish
Ashish - avatar
6 Réponses
+ 5
Say you have a few terabytes of data in your database. It can't all fit in memory. However, you have noticed that records used today tend to be used multiple times. This is when creating a cache makes sense. Instead of reading the records every time your users access them, you store them in memory for later use. Normally, a variable size list structure is used. The oldest records are replaced by the newer ones so the list doesn't take over all memory.
8th Sep 2019, 12:51 AM
John Wells
John Wells - avatar
+ 4
Searching the database may not make sense doing caching. However, if you want a certain summary data, caching and maintaining that data in memory could be much better than calculating it each time you need that report. You must know all the usage of the data to select what makes sense to cache. Storing stuff that won't be used is a waste of time and memory.
8th Sep 2019, 3:21 AM
John Wells
John Wells - avatar
+ 3
Picking a too small or large cache is also useless. Too small and what you need was just replaced so unavailable. Too large and the search to find what you are looking for could be more expensive than reading it once more.
8th Sep 2019, 3:27 AM
John Wells
John Wells - avatar
+ 1
John Wells Sir, if the record is a part of database, then caching it would cost us some memory, right? Say you have a database storing info about bunch of users with database having the size of few TB, and now we want to access the info about 100 users and we have cached it knowing we need this in every iteration, so does it pick them from the database if it is having the size of TBs and it cant all fit in memory?
8th Sep 2019, 3:14 AM
Ashish
Ashish - avatar
+ 1
Oh! I get it now. Thanks
8th Sep 2019, 10:07 AM
Ashish
Ashish - avatar