Locality of Reference

Caching works because of a very simple property exhibited to one degree or another by all types of code and data: locality of reference. We generally find it useful to talk about two types of locality of reference: spatial locality and temporal locality.

Spatial locality

Spatial locality is a fancy label for the general rule that if the CPU needs an item from memory at any given moment, it’s likely to need that item’s neighbors next.

Temporal locality

Temporal locality is the name we give to the general rule that if an item in memory was accessed once, it’s likely to be accessed again in the near future.

Depending on the type of application, both code and data streams can exhibit spatial and temporal locality.

Spatial Locality ...

Get Inside the Machine now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.