캐시 클리어
curl --request POST \
--url https://sajuapi.dev/v1/cache/clear \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"type": "<string>",
"profile_id": "<string>",
"fortune_date": "<string>",
"confirm": true
}
'import requests
url = "https://sajuapi.dev/v1/cache/clear"
payload = {
"type": "<string>",
"profile_id": "<string>",
"fortune_date": "<string>",
"confirm": True
}
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({
type: '<string>',
profile_id: '<string>',
fortune_date: '<string>',
confirm: true
})
};
fetch('https://sajuapi.dev/v1/cache/clear', 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/v1/cache/clear",
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([
'type' => '<string>',
'profile_id' => '<string>',
'fortune_date' => '<string>',
'confirm' => true
]),
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/v1/cache/clear"
payload := strings.NewReader("{\n \"type\": \"<string>\",\n \"profile_id\": \"<string>\",\n \"fortune_date\": \"<string>\",\n \"confirm\": true\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/v1/cache/clear")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"<string>\",\n \"profile_id\": \"<string>\",\n \"fortune_date\": \"<string>\",\n \"confirm\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://sajuapi.dev/v1/cache/clear")
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 \"type\": \"<string>\",\n \"profile_id\": \"<string>\",\n \"fortune_date\": \"<string>\",\n \"confirm\": true\n}"
response = http.request(request)
puts response.read_body시스템
캐시 클리어
POST
/
v1
/
cache
/
clear
캐시 클리어
curl --request POST \
--url https://sajuapi.dev/v1/cache/clear \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"type": "<string>",
"profile_id": "<string>",
"fortune_date": "<string>",
"confirm": true
}
'import requests
url = "https://sajuapi.dev/v1/cache/clear"
payload = {
"type": "<string>",
"profile_id": "<string>",
"fortune_date": "<string>",
"confirm": True
}
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({
type: '<string>',
profile_id: '<string>',
fortune_date: '<string>',
confirm: true
})
};
fetch('https://sajuapi.dev/v1/cache/clear', 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/v1/cache/clear",
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([
'type' => '<string>',
'profile_id' => '<string>',
'fortune_date' => '<string>',
'confirm' => true
]),
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/v1/cache/clear"
payload := strings.NewReader("{\n \"type\": \"<string>\",\n \"profile_id\": \"<string>\",\n \"fortune_date\": \"<string>\",\n \"confirm\": true\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/v1/cache/clear")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"<string>\",\n \"profile_id\": \"<string>\",\n \"fortune_date\": \"<string>\",\n \"confirm\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://sajuapi.dev/v1/cache/clear")
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 \"type\": \"<string>\",\n \"profile_id\": \"<string>\",\n \"fortune_date\": \"<string>\",\n \"confirm\": true\n}"
response = http.request(request)
puts response.read_bodyv1 Enterprise API (Coming Soon)이 엔드포인트는 Enterprise 버전에서 제공될 예정입니다.
현재는 v0 API를 사용하세요.
이 엔드포인트는 관리자 권한이 필요합니다. 캐시 삭제 후 일시적으로 응답 시간이 증가할 수 있습니다.
Request Body 파라미터
string
default:"all"
삭제할 캐시 유형입니다.
all, fortunes, calculations, profiles 중 하나입니다.string
특정 프로필의 캐시만 삭제합니다. 지정하지 않으면 전체를 대상으로 합니다.
string
특정 날짜의 운세 캐시만 삭제합니다. ISO 8601 형식(YYYY-MM-DD)입니다.
boolean
required
캐시 삭제를 확인합니다.
true로 설정해야 삭제가 진행됩니다.Response
성공
캐시 삭제에 성공하면 삭제된 항목 수가 반환됩니다.실패
| 상태 코드 | 에러 타입 | 설명 |
|---|---|---|
| 400 | validation_error | confirm 파라미터가 누락됨 |
| 401 | authentication_error | API 키가 유효하지 않음 |
| 403 | forbidden | 관리자 권한이 없음 |
| 429 | rate_limited | 요청 한도 초과 |
요청 예시
# 전체 캐시 삭제
curl -X POST https://api.sajuapi.dev/v1/cache/clear \
-H "X-API-Key: bs_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"type": "all",
"confirm": true
}'
# 특정 프로필 캐시만 삭제
curl -X POST https://api.sajuapi.dev/v1/cache/clear \
-H "X-API-Key: bs_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"type": "fortunes",
"profile_id": "prf_abc123def456",
"confirm": true
}'
# 특정 날짜의 운세 캐시 삭제
curl -X POST https://api.sajuapi.dev/v1/cache/clear \
-H "X-API-Key: bs_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"type": "fortunes",
"fortune_date": "2025-01-16",
"confirm": true
}'
// 전체 캐시 삭제
const response = await fetch(
'https://api.sajuapi.dev/v1/cache/clear',
{
method: 'POST',
headers: {
'X-API-Key': 'bs_live_xxx',
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'all',
confirm: true
})
}
);
const result = await response.json();
console.log(`삭제된 항목: ${result.cleared_count}`);
// 특정 프로필 캐시만 삭제
const profileClear = await fetch(
'https://api.sajuapi.dev/v1/cache/clear',
{
method: 'POST',
headers: {
'X-API-Key': 'bs_live_xxx',
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'fortunes',
profile_id: 'prf_abc123def456',
confirm: true
})
}
).then(r => r.json());
import requests
# 전체 캐시 삭제
response = requests.post(
'https://api.sajuapi.dev/v1/cache/clear',
headers={'X-API-Key': 'bs_live_xxx'},
json={
'type': 'all',
'confirm': True
}
)
result = response.json()
print(f"삭제된 항목: {result['cleared_count']}")
# 특정 프로필 캐시만 삭제
profile_clear = requests.post(
'https://api.sajuapi.dev/v1/cache/clear',
headers={'X-API-Key': 'bs_live_xxx'},
json={
'type': 'fortunes',
'profile_id': 'prf_abc123def456',
'confirm': True
}
).json()
응답 예시
전체 캐시 삭제
{
"success": true,
"type": "all",
"cleared": {
"fortunes": 12580,
"calculations": 5420,
"profiles": 0
},
"cleared_count": 18000,
"cleared_at": "2025-01-16T09:00:00Z"
}
특정 프로필 캐시 삭제
{
"success": true,
"type": "fortunes",
"profile_id": "prf_abc123def456",
"cleared": {
"fortunes": 45
},
"cleared_count": 45,
"cleared_at": "2025-01-16T09:00:00Z"
}
특정 날짜 캐시 삭제
{
"success": true,
"type": "fortunes",
"fortune_date": "2025-01-16",
"cleared": {
"fortunes": 3250
},
"cleared_count": 3250,
"cleared_at": "2025-01-16T09:00:00Z"
}
CacheClearResult 객체
| 필드 | 타입 | 설명 |
|---|---|---|
success | boolean | 삭제 성공 여부입니다. |
type | string | 삭제된 캐시 유형입니다. |
profile_id | string | 대상 프로필 ID입니다 (지정한 경우). |
fortune_date | string | 대상 날짜입니다 (지정한 경우). |
cleared | object | 유형별 삭제된 항목 수입니다. |
cleared_count | integer | 총 삭제된 항목 수입니다. |
cleared_at | string | 삭제 완료 시간입니다. |
캐시 유형
| 유형 | 설명 | TTL |
|---|---|---|
fortunes | 생성된 운세 캐시 | 24시간 (일간), 1주일 (연간) |
calculations | 사주 계산 결과 캐시 | 영구 (프로필 삭제 시 삭제) |
profiles | 프로필 조회 캐시 | 1시간 |
활용 사례
운세 재생성
프로필 정보가 수정된 후 캐시를 삭제하여 새로운 운세를 생성할 수 있습니다.// 프로필 수정 후 캐시 삭제
async function updateProfileAndClearCache(profileId, updateData) {
// 1. 프로필 수정
await fetch(`/v1/profiles/${profileId}`, {
method: 'PUT',
headers: {
'X-API-Key': 'bs_live_xxx',
'Content-Type': 'application/json'
},
body: JSON.stringify(updateData)
});
// 2. 해당 프로필의 캐시 삭제
await fetch('/v1/cache/clear', {
method: 'POST',
headers: {
'X-API-Key': 'bs_live_xxx',
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'fortunes',
profile_id: profileId,
confirm: true
})
});
// 3. 새로운 운세 생성
const fortune = await fetch('/v1/fortunes', {
method: 'POST',
headers: {
'X-API-Key': 'bs_live_xxx',
'Content-Type': 'application/json'
},
body: JSON.stringify({
profile_id: profileId,
fortune_type: 'daily'
})
}).then(r => r.json());
return fortune;
}
일괄 캐시 초기화
자정에 모든 일간 운세 캐시를 삭제하여 새로운 날의 운세를 준비할 수 있습니다.// 자정에 실행 (Cron job)
async function resetDailyCache() {
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
const dateStr = yesterday.toISOString().split('T')[0];
const result = await fetch('/v1/cache/clear', {
method: 'POST',
headers: {
'X-API-Key': 'bs_live_xxx',
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'fortunes',
fortune_date: dateStr,
confirm: true
})
}).then(r => r.json());
console.log(`어제(${dateStr}) 캐시 삭제: ${result.cleared_count}개`);
}
캐시 삭제는 감사 로그에 기록됩니다. 빈번한 캐시 삭제는 비용 증가로 이어질 수 있으므로 주의하세요.
⌘I