What is cache?
In programming, collection of data stored for future use & which can be retrieved faster.
How do you achieve this in your code?
Example in the thread
In programming, collection of data stored for future use & which can be retrieved faster.
How do you achieve this in your code? Example in the thread

This is a simple class defining Line.
If you see carefully, we have a var distance only accessible via its getter method getDistance.
How is caching happening here?
Thread contd.
If you see carefully, we have a var distance only accessible via its getter method getDistance.
How is caching happening here?
Thread contd.
Even if we don't have distance in the class variables, we can get the distance from its getter by calculating it everytime.
But for faster retrieval of data, we store the distance and calculate only if coordinates changed.This means we are caching the distance.
The code is C++ pseudocode.
private data cannot be accessed outside the class.
public data can access private data.
public data can be accessed outside the class.
private data cannot be accessed outside the class.
public data can access private data.
public data can be accessed outside the class.
Read on Twitter