An n-way set associative cache is a cache that is chopped up in sections called sets. And each set can hold n-blocks.
A cache-address can be broken up up in 3 parts.
- the offset within the block
- the index that identifies the set
- the tag that identifies the block in the set.
When a request comes in, the index is calculated to identify the set. Then the tags of all blocks in the set are checked. And when a block with a matching tag is found, the right bytes are returned based on the offset.
A direct mapped cached is effectively a 1 way set associative cache.
So associativity doesn't mean the number of blocks the cache can hold, but the number of blocks a set within the cache can hold.
The big advantage of a n-way set associative cache compared to a direct mapped cache, is the latter can only have a single block for a set of addresses and the former can hold multiple blocks for a set of addresses.