캐시 삭제
curl --request POST \
--url https://sajuapi.dev/api/clear-cache \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"userName": "<string>"
}
'import requests
url = "https://sajuapi.dev/api/clear-cache"
payload = { "userName": "<string>" }
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({userName: '<string>'})
};
fetch('https://sajuapi.dev/api/clear-cache', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://sajuapi.dev/api/clear-cache",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'userName' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sajuapi.dev/api/clear-cache"
payload := strings.NewReader("{\n \"userName\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://sajuapi.dev/api/clear-cache")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"userName\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://sajuapi.dev/api/clear-cache")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"userName\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body시스템
캐시 삭제
POST
/
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>"
}
'import requests
url = "https://sajuapi.dev/api/clear-cache"
payload = { "userName": "<string>" }
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({userName: '<string>'})
};
fetch('https://sajuapi.dev/api/clear-cache', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://sajuapi.dev/api/clear-cache",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'userName' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sajuapi.dev/api/clear-cache"
payload := strings.NewReader("{\n \"userName\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://sajuapi.dev/api/clear-cache")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"userName\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://sajuapi.dev/api/clear-cache")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"userName\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body특정 사용자의 캐시된 운세 데이터를 삭제합니다.
프로필 삭제 시 또는 운세 재생성이 필요할 때 사용합니다.
Request Body
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}개`);
import requests
response = requests.post(
'https://sajuapi.dev/api/clear-cache',
json={
'userName': '김철수'
}
)
result = response.json()
print(f"삭제된 캐시: {result['deletedCount']}개")
curl -X POST https://sajuapi.dev/api/clear-cache \
-H "Content-Type: application/json" \
-d '{"userName": "김철수"}'
응답 예시
{
"success": true,
"deletedCount": 15,
"deletedKeys": [
"fortune:김철수:2025-01-15:haiku",
"fortune:김철수:2025-01-16:haiku",
"character:김철수:haiku",
"tendency:김철수:haiku",
"radar:김철수:haiku"
]
}
삭제되는 캐시
| 캐시 유형 | 키 패턴 | 설명 |
|---|---|---|
| Fortune | fortune:{userName}:{date}:{model} | 일일 운세 (최근 7일) |
| Character | character:{userName}:{model} | 투자 성격 분석 |
| Tendency | tendency:{userName}:{model} | 투자 성향 분석 |
| Radar | 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();
}
캐시는 Upstash Redis에 저장됩니다. 캐시 삭제 실패 시에도 자연스럽게 TTL에 의해 만료됩니다.
모든 모델(haiku, sonnet, gpt4o, gemini)의 캐시가 함께 삭제됩니다.
⌘I