I met two cases in final exam. First case memory fetch information from location like: 0x101,0x102,0x101,0x102,0x101,0x102,0x101,0x102.
Second case memory fetch information from location like: 0x101,0x101,0x101,0x101,0x111,0x109,0x102,0x100.
The question is in which case it use temporal locality.
Here is my point: In the first case. I think in reality when we access 0x101,the memory will also access 0x102 into cache. Then in the following six fetch, there will be no penalty. That means in this case we only have one cache miss. Here I think we benefit from both temporal locality and spatial locality. while in the second case in the first four step we benefit from temporal locality but in the following step we do not have temporal locality. Actually this leads to more cache miss than first choice. I think both are right but we can only have one answer so I feel confused.
It's definitely the 2nd choice. The question is clear enough: you are explicitly making use of temporal locality in the second case because you're accessing 0x101 multiple times in a row.
See this question: Spatial vs. Temporal locality
You are right in saying that the first case also uses temporal locality, but I'd say it gears towards spatial locality because you are alternating between 2 neighbour positions, thus, cache misses are minimized because of spatial locality, not because of temporal locality.
In the second case, cache misses are minimized because of temporal locality. Remember that temporal locality says that if you accessed position X right now, you will likely do so again very soon. This is the property explored in the second case.