Dictionary
Caching
Caching is the practice of storing copies of data or computed results in a temporary storage layer so that future requests for the same information can be served faster without repeating the original computation or network fetch. In web development, caching operates at multiple levels: the browser cache stores static assets locally on the user's device, CDN caches distribute content copies to edge servers worldwide, server-side caches like Redis or Memcached store database query results and rendered pages in memory, and application-level caches store computed data to avoid redundant processing.
HTTP caching is controlled through response headers that instruct browsers and intermediary caches on how to handle stored content. The Cache-Control header is the primary mechanism, with directives like max-age setting how many seconds a response remains valid, no-cache requiring revalidation with the origin server before use, and no-store preventing caching entirely for sensitive data. The ETag header provides a fingerprint for a specific version of a resource, enabling efficient conditional requests where the browser asks the server whether its cached version is still current rather than downloading the full resource again. Properly configured cache headers can eliminate the majority of redundant network requests, dramatically reducing both server load and page load times for returning visitors.
The classic challenge in caching is cache invalidation, famously described as one of the two hard problems in computer science. When the underlying data changes, cached copies must be updated or cleared to prevent users from seeing stale content. Strategies vary by cache layer: versioned file names with content hashes ensure browsers fetch new JavaScript and CSS when code changes, CDN purge APIs allow programmatic cache clearing when content is updated in the CMS, and server-side caches use TTL expiration or event-driven invalidation triggered by database writes. Getting caching right delivers enormous performance gains; getting it wrong causes users to see outdated content and developers to spend hours debugging why changes are not appearing.