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


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.



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.