Communitygithub.com

캐싱 전략

Redis 캐싱, CDN 캐시 헤더, stale-while-revalidate, 캐시 무효화, React Query.

캐싱 전략란 무엇인가요?

이 스킬은 브라우저, CDN, 애플리케이션, 데이터베이스 등 모든 계층에서의 캐싱 전략을 포괄적으로 다룹니다. 특히 `stale-while-revalidate` 패턴을 활용하여 콘텐츠를 빠르게 제공하면서도 백그라운드에서 신선도를 유지하는 방법을 제시합니다. Redis를 활용한 캐시 외부(캐시-어사이드) 패턴, React Query/TanStack Query에서의 `staleTime` 및 `gcTime` 설정, Next.js에서의 ISR 및 `unstable_cache` 사용법을 예제 코드와 함께 설명합니다. 또한, 태그 기반 무효화 등 캐시 무효화 전략을 다루어 데이터 변경 시 일관성을 유지하는 방법을 제공합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/caching-strategy

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

캐싱 전략은(는) 무엇을 하나요?

규칙

  • 모든 계층에서 캐싱: 브라우저(Cache-Control), CDN(엣지), 애플리케이션(Redis), 데이터베이스(쿼리 캐시)
  • 약간 오래된 콘텐츠에는 stale-while-revalidate 사용 — 빠르게 제공하고, 백그라운드에서 새로고침
  • Cache-Control 헤더: 해시된 정적 자산은 public, max-age=31536000, immutable; 동적 페이지는 public, s-maxage=60, stale-while-revalidate=300
  • Redis 캐싱: JSON으로 직렬화, 모든 키에 TTL 설정, 네임스페이스 키 사용 (cache:users:123)
  • React Query / TanStack Query: staleTime(데이터가 신선한 기간)과 gcTime(메모리 보관 기간) 설정
  • 쓰기 시 무효화 — 데이터가 변경되면 캐시 항목을 즉시 삭제하거나 업데이트
  • 캐시-어사이드 패턴 사용: 먼저 캐시 확인, 미스 시 원천에서 가져와 캐시에 쓰기
  • Next.js의 경우: 서버 컴포넌트에 ISR(revalidate), unstable_cache, fetch 캐시 활용
  • 태그 기반 무효화: 캐시된 항목을 엔티티 유형별로 태깅, 변이 시 해당 태그의 모든 항목 무효화

패턴

// Redis를 사용한 캐시-어사이드 패턴
async function getCachedUser(id: string) {
  const cached = await redis.get(`user:${id}`);
  if (cached) return JSON.parse(cached);
  const user = await db.user.findUnique({ where: { id } });
  await redis.set(`user:${id}`, JSON.stringify(user), "EX", 3600);
  return user;
}

피해야 할 것

  • TTL 없이 캐싱 — 오래된 데이터가 무기한 유지됨
  • 공유 CDN 캐시에 사용자별 데이터 캐싱 — private 또는 Vary 헤더 사용
  • 캐시 스탬피드: 잠금이나 stale-while-revalidate를 사용하여 떼밀림(thundering herd) 방지
  • 오류 응답 캐싱 — 성공한 결과만 캐시

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

관련 스킬