# Cache Organization source: Week08 memory-cache p.5~p.13 [video link](https://www.youtube.com/watch?v=UeLbipDWxJs&ab_channel=soclab) ## why we need cache? ![memory-cache-5](https://hackmd.io/_uploads/H1gcT3eET.jpg) 1. Temporal Locality: 剛被使用過的資料很可能短時間內會被重複使用 2. Spatial Locality: 剛被使用過的資料,鄰近位址的資料很可能會被使用 ## Cache Operations ![memory-cache-6](https://hackmd.io/_uploads/S1CqTnlVa.jpg) * Read: 1. Cache hit: cache有要用的資料,直接從cache傳回去 2. cache miss: cache沒有要用的資料,清一個位子出來存從main memory傳回來的資料( **read-allocate** ) * Write: 1. Cache hit: cache有這個位址,直接寫在cache 2. cache miss: cache沒有這個位址,清一個位子寫入cache( **write-allocate** ),或是直接寫到main memory * Hit Rate: Hit的比例 * Cache Line: store data in blocks,也就是一次cache很多筆資料,e.g.: 資料長度8bit,cache line大小64 bit,以8筆資料為單位在做cache operation ![memory-cache-7](https://hackmd.io/_uploads/BkM2a2gVp.jpg) ![memory-cache-8](https://hackmd.io/_uploads/BJJ6a2xET.jpg) ![memory-cache-9](https://hackmd.io/_uploads/r1-kA3eVp.jpg) ![memory-cache-10](https://hackmd.io/_uploads/H1WkCnxE6.jpg) About the chart: **Not improve much when cache size is large** ![memory-cache-11](https://hackmd.io/_uploads/ryb1R3lV6.jpg) ![memory-cache-12](https://hackmd.io/_uploads/SJWyRheV6.jpg) ![memory-cache-13](https://hackmd.io/_uploads/HyWk0ngE6.jpg)