I have asked this cache question to a couple of senior positions

LORY
7 min readSep 28, 2023

When I see “I boost system performance X times faster by using Y cache”

Cache is hard

There are only two hard things in Computer Science: cache invalidation and naming things.

  • - Phil Karlton

When we work with cache, it brings performance, but it also brings problems. the biggest problem is — data consistency.

Let’s walk it through with interview details.

Story#1 — cache in the small world

Many candidates are not aware there is a cache at the CPU level.

“You mentioned here fixed a critical issue in multi-threading code, could you explain what was that?”.

“Sure, I volatile my variable which is shared across multi-threads.”. he answered.

“So what is the value type of this volatile, and why are you using it”?

“It is an integer, to make sure all threads can get the updated value of the variable”, he said.

“Do you know the cost of using it? And could you pls explain why it works?”.

“I’m not sure about it, it just works. without volatile, multiple threads seeing different values,” he said.

Actually, he was not wrong, I just want to dig into more to touch the limit (was a senior role of C#).

--

--

LORY
LORY

Written by LORY

A channel which focusing on developer growth and self improvement