How Caching Works? | Why is Caching Important?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
but the two main reasons we need caching is first of all lookup from this ssd or even hard disks is slower compared to ram and second of all the computation the computation cost is higher right hey everyone welcome back and in this video we'll be discussing about caching which is one of the most important things to learn as a back-end developer why you need caching and how does that exactly work especially with regards to how databases work let's go also if you're new here make sure you leave a like to the video subscribe to the channel to receive daily updates on front-end back-end web development and more on programming side this video is a part of code dam's t-shirt giveaway program for the month if you want to take part and win an amazing goal damn t-shirt all you have to do is leave a comment on this video about what you think and that's it you are eligible if your comment gets a heart from code damn you will win a t-shirt for absolutely free all right so in this video i'll focus more on the caching part from the concept from the angle of databases right because that is one of the most used area of caching sure you can cache all sorts of things and all sorts of computations but database lookups are very popular now the reason for that is let's say you have a database sitting in front of here right and let's assume this is a sequel or no seeker i mean it's pretty much the same thing in terms of caching but you perform a request you do any select star or whatever operation now ideally the reason databases can persist data is that they do not store your data on ram right so you have two components the for storage the first one right here which we discussed is ram and the second one is a hard disk right a hard disk or you know ssd or hdd or whatever you want to call it this is a permanent storage and this is a temporary storage which we all know from class 6 but the thing which we probably don't know is that databases have to store their data on hard disks or ssds or whatever the reason for this is because rams are temporary and if the power loses you're going to lose out that data but the lookup this lookup is slow this database this hard disk lookup is slow so databases use all sorts of optimizations in order to keep some data in the memory some data on the hard disk and so on but the two main reasons we need caching is first of all lookup from the ssd or even hard disks is slower compared to ram and second of all the computation the computation cost is higher right and for the most part i think we focus more on this thing this part comes more handy if you have large data right so if you have large data with tens of thousands or hundreds of thousands of rows or documents if it's a nosql database then this becomes more suitable point other than that if you have complex queries like for example in mongodb if you're running an aggregate query that's much complex than just a simple query for the database engine therefore the computation part is the main point there now how does a redis like or you know any mem cache radius any caching system solves this well you see that it's basically nothing it's redis is a very simple software which is a wrapper around how you can store and get and maybe expire things inside of your ram right if this is your application right here you're gonna see that whenever you call your backend for example whenever you call the logic layer that logic layer first of all checks that if that result of that query is existing in cache and when it checks that if it exists in cache it's actually just squaring ram in a structured way right so redis is just your ram which you can query with the software right so reader sits in your ram and optimizes these lookups which you perform but on the ram storage right you can directly access the ram and you know just read and write bits and bytes but it's always nice to have certain mechanisms and certain things and certain features built in for example you can have an expiry setup would set ex you can set the key or not depending on if the key exists or not so these two methods for example are very useful for radius and so on and so forth but this video is more about caching so let's not dive deep into reddish because we have a full course on that on coldham if you are interested you can check out the redis caching concepts on codedown.com but the important point here is that redis is just ram right in a very simple way the redis is just ram which allows you to store these lookup or these computation results directly without actually going through all this database engine and then the hard disk and so on so an ideal system should look something like this where you have a client which accesses the api somehow whether it's api gateway whether it's your own managed ec2 instances and so on if this is a query the backend sees that there's a query it performs the query but it first checks redis or any caching solution if you already have a cache against that if the cache is found then you return the query if it is not found you run it through the database which you know in most of the cases if it's i mean if it's a cold query it goes to the desk and using the database engine which is the primary engine how it queries the file system gets the data ideally stores it back into cache for any future use and be done with it right so red is in this case acts more as of a as of a query booster instead of a critical system because if red is let's say for some reason is not able to store this query or you know forgets then you always will hit the snow branch and transparently you will get the result back all the time but this right here this component speeds up this whole thing because once the square is hit then for the next million hits for example in a single day you might just hit this route right here which is probably 2x 3x faster depending on how complex your query is how complex your lookup is now we haven't discussed about what happens here obviously because right here inside of the database as well database optimizes certain query results it sees that hey if you're accessing this state out way too often i'm just going to keep that information in the ram myself right so if you're accessing certain queries certain indexes i mean for indexes i believe it keeps it in the ram for the most part but even for certain queries the database engine might do it right but anyway it's always a good idea to have a caching system especially if you have computationally heavy queries or if you have queries which require a very large lookup for the databases right 10 000 20 000 quick records and so on so yeah that's pretty much it for this video if you enjoyed it make sure you leave a like and hit the bell icon subscribe to the channel and let me know in the comments what do you think about caching that is all for this one i'm gonna see you in the next video really soon [Music] [Music] you
Info
Channel: Mehul - Codedamn
Views: 29,490
Rating: undefined out of 5
Keywords: web development, codedamn, mehul mohan, full stack development, full stack web development, Caching - Simply Explained, Why is Caching Important, How Caching Works, What is Distributed Caching? Explained with Redis, caching, types of caching, what is caching, redis, cache, redis cache, database, redis labs, learn redis, redis database, redis tutorial, redis basics, cache miss, cache busting, response time, caching crash course, redis caching, learn redis caching
Id: ASP7O5fDpSg
Channel Id: undefined
Length: 7min 21sec (441 seconds)
Published: Wed Sep 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.