Skip to main content
POST
https://sajuapi.dev
/
api
/
clear-cache
캐시 삭제
curl --request POST \
  --url https://sajuapi.dev/api/clear-cache \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <api-key>' \
  --data '
{
  "userName": "<string>"
}
'
특정 사용자의 캐시된 운세 데이터를 삭제합니다. 프로필 삭제 시 또는 운세 재생성이 필요할 때 사용합니다.

Request Body

userName
string
required
캐시를 삭제할 사용자 이름입니다.

Response

성공

캐시 삭제에 성공하면 삭제된 항목 수가 반환됩니다.

요청 예시

const response = await fetch('/api/clear-cache', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    userName: '김철수'
  })
});

const result = await response.json();
console.log(`삭제된 캐시: ${result.deletedCount}개`);

응답 예시

{
  "success": true,
  "deletedCount": 15,
  "deletedKeys": [
    "fortune:김철수:2025-01-15:haiku",
    "fortune:김철수:2025-01-16:haiku",
    "character:김철수:haiku",
    "tendency:김철수:haiku",
    "radar:김철수:haiku"
  ]
}

삭제되는 캐시

캐시 유형키 패턴설명
Fortunefortune:{userName}:{date}:{model}일일 운세 (최근 7일)
Charactercharacter:{userName}:{model}투자 성격 분석
Tendencytendency:{userName}:{model}투자 성향 분석
Radarradar:{userName}:{model}레이더 차트 데이터

사용 사례

프로필 삭제 시

사용자가 프로필을 삭제하면 관련 캐시도 함께 삭제해야 합니다.
async function deleteProfile(profileId, userName) {
  // 1. 로컬 스토리지에서 프로필 삭제
  const profiles = JSON.parse(localStorage.getItem('saju_profiles') || '{}');
  delete profiles[profileId];
  localStorage.setItem('saju_profiles', JSON.stringify(profiles));

  // 2. 서버 캐시 삭제 (fire-and-forget)
  fetch('/api/clear-cache', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ userName })
  }).catch(() => {
    // 실패해도 무시 (캐시는 자연스럽게 만료됨)
  });
}

운세 강제 재생성

사용자가 운세를 다시 생성하고 싶을 때 캐시를 삭제합니다.
async function regenerateFortune(userName, date, model) {
  // 1. 캐시 삭제
  await fetch('/api/clear-cache', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ userName })
  });

  // 2. 새로운 운세 생성
  const fortune = await fetch('/api/daily-fortune', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ saju, userName, date, model })
  });

  return fortune.json();
}
캐시는 Upstash Redis에 저장됩니다. 캐시 삭제 실패 시에도 자연스럽게 TTL에 의해 만료됩니다.
모든 모델(haiku, sonnet, gpt4o, gemini)의 캐시가 함께 삭제됩니다.