캐싱 (Caching)
자주 액세스하는 데이터를 더 빠른 임시 저장소에 보관하여 응답 속도를 높이는 기술.
캐싱은 현대 컴퓨팅의 거의 모든 수준에서 작동합니다. CPU 캐시, 애플리케이션 계층의 Redis/Memcached, 네트워크 계층의 CDN, 그리고 사용자 하드 디스크에 데이터를 저장하는 웹 브라우저 캐시가 모두 같은 원리로 작동합니다.
graph LR
Center["캐싱 (Caching)"]:::main
Rel_file_systems["file-systems"]:::related -.-> Center
click Rel_file_systems "/terms/file-systems"
Rel_cpu_cache["cpu-cache"]:::related -.-> Center
click Rel_cpu_cache "/terms/cpu-cache"
Rel_cache["cache"]:::related -.-> Center
click Rel_cache "/terms/cache"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧒 5살도 이해할 수 있게 설명
어머니에게 전화할 때마다 다른 방에 있는 두꺼운 전화번호부를 뒤져야 한다고 상상해 보세요. 너무 오래 걸리겠죠? 캐싱은 포스트잇에 번호를 적어 모니터에 붙여두는 것과 같습니다. 포스트잇은 작지만 가장 필요한 정보를 즉시 볼 수 있게 해줍니다.
🤓 Expert Deep Dive
하드웨어 캐시(L1/L2/L3)는 시간적, 공간적 지역성(Locality) 원리를 따릅니다. 캐시는 용량이 작기 때문에 공간을 확보하기 위해 LRU(Least Recently Used)와 같은 퇴거(Eviction) 정책을 사용합니다. 필 칼튼이 말했듯 프로그래밍에서 가장 어려운 문제 중 하나는 '캐시 무효화(Cache Invalidation)'입니다. 원본 데이터가 변경되었을 때 캐시의 오래된 데이터를 정확히 삭제하는 작업입니다.
❓ 자주 묻는 질문
Why not just make the cache big enough to hold everything?
Cost and physics. Cache storage (like SRAM inside a CPU or RAM for a database) is extremely fast but very expensive per gigabyte. Primary storage (like hard drives or SSDs) is much cheaper but much slower. Caching provides the best of both worlds.
What does it mean to 'clear your cache'?
When you clear your web browser's cache, you are deleting the temporary files (images, scripts) it saved from websites you visited. This is often necessary if a website updates its design but your browser is stubbornly loading the old, cached version.
What is a 'cache miss'?
A cache miss occurs when a system looks for data in the cache but doesn't find it. It must then fetch the data from the slower primary storage, which takes longer, and then it typically copies that data into the cache for next time.