cURL
curl --request POST \ --url https://sajuapi.dev/api/clear-cache \ --header 'Content-Type: application/json' \ --header 'X-API-Key: <api-key>' \ --data ' { "userName": "<string>" } '
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" ] }
fortune:{userName}:{date}:{model}
character:{userName}:{model}
tendency:{userName}:{model}
radar:{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(); }