Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AGiallelis/1a676f0dce4febd0c2c6d7e3b4bafc9f to your computer and use it in GitHub Desktop.
Save AGiallelis/1a676f0dce4febd0c2c6d7e3b4bafc9f to your computer and use it in GitHub Desktop.
In general, a cache is a "more local" copy of a memory resource that you want to access.
Its a copy that is faster to access than the original, but that memory is also more expensive.
This link, provides some measurements that illustrate the benefits: http://norvig.com/21-days.html#answers
Disk cache is RAM memory, that contains a copy of the information on the disk.
Typically, when you access something on the drive, the whole page is brought into cache, on the assumption that the next access will be in that page.
The first disk seek might take 8ms, while seeks from cache 100 ns (many times faster - note nanoseconds instead of milliseconds)
Memory cache is the same concept, but the cache is located on the CPU chip. So the original memory access is 100ns, the L1 cache access can be 0.5 ns.
Browser cache is similar, but stores resources like images, javascript files, etc. on your hard-drive instead of the web page.
Once you access a website, these static resources are stored locally in the browser cache for quicker access the second time you need it.
Using the data from the link above, your access to an image on the web might take 150ms initially, but the second time only 8ms.
Memory and Disk cache implementations will try to guess what you need to use next, while browser caches keep a local copy in case you need to use it again.
@RamiroPrather
Copy link

A cache is a "local" copy of the memory resource you want to access. The disk cache is RAM.

@shubham08gupta
Copy link

Everywhere I've read it says disk cache is not RAM. It's stored on hard disk (HDD) or SSD. So disk cache can stay for much longer than in-memory cache (which is stored in RAM).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment