API Documentation
Gabay sa Response Caching at CDN Integration
Optimize ang performance ng Smart Money API gamit ang matalinong caching strategies. Alamin ang HTTP cache headers, ETag validation, CDN integration, at client-side caching patterns para mabawasan ang latency at bandwidth costs.
Na-publish noong Marso 21, 2026
•
16 min read
•
Performance
Pangkalahatang-ideya ng Caching
Ang mga endpoint ng Smart Money API ay naghahatid ng cryptocurrency market data na nagbabago sa iba't ibang frequency. Ang ilang data (whale addresses, funding rates) ay nag-u-update kada ilang segundo, habang ang ibang data (historical analysis, educational content) ay nananatiling static sa loob ng ilang oras. Ang matalinong caching ay makabuluhang nagpapabuti sa performance at nagbabawas ng costs.
Ang Smart Money API ay nagpapatupad ng three-tier caching strategy:
- CDN Edge Cache — Global content delivery na may automatic cache invalidation
- HTTP Browser Cache — Client-side caching gamit ang standard HTTP headers
- Application Cache — In-memory caching para sa madalas ma-access na datasets
Performance Insight: Ang mga cached response ay naghahatid ng 50-100x na mas mabilis kaysa sa fresh API requests at makabuluhang nakakatipid sa bandwidth. Ang tamang cached integration ay maaaring magbawas ng data transfer ng 70-85%.
Ang bawat response ng Smart Money API ay may kasamang cache directives na nagsasabi sa mga client at CDN kung gaano katagal valid ang data. Ang pag-unawa sa mga directives na ito at tamang pagpapatupad ay mahalaga para sa optimal performance.
Mga Batayan ng Caching
Ang HTTP caching ay gumagana batay sa response headers na nagpapahiwatig kung ang content ay pwedeng i-cache at kung gaano katagal.
Cache-Control Header
Ang pangunahing mekanismo para kontrolin ang cache behavior. Ang bawat response ng Smart Money API ay may kasamang Cache-Control header na nagtutukoy ng:
- max-age — Tagal sa segundo kung gaano katagal valid ang response
- public/private — Kung pwedeng i-store ng intermediate caches
- must-revalidate — Kung kailangang i-check ang freshness bago i-serve
- no-store — Huwag i-cache ang sensitive data
Halimbawa ng Cache Headers
Ang iba't ibang endpoint ay may iba't ibang cache requirements:
// Whale address data (nag-u-update kada 5 minuto)
Cache-Control: public, max-age=300
ETag: "abc123def456"
// Real-time funding rates (nag-u-update kada segundo)
Cache-Control: public, max-age=1
ETag: "xyz789abc123"
// Historical data (hindi nagbabago)
Cache-Control: public, max-age=86400, immutable
ETag: "static-content-v1"
Cache Duration by Endpoint Type
| Data Type |
Cache Duration |
Use Case |
| Real-time Funding |
1-5 seconds |
Live trading, position sizing |
| Whale Movements |
5 minutes |
Signal confirmation, alerts |
| Daily OHLCV |
1 hour |
Technical analysis, charts |
| Historical Analysis |
24 hours |
Backtesting, research |
| Static Content |
7 days |
API docs, guides, configuration |
Kunin ang iyong API key sa loob ng 30 segundo
Handa nang mag-build? Kumuha ng libreng API key (200 calls/day, no card) at simulan ang pagkuha ng live whale, funding at on-chain data.
Kunin ang iyong API key →
ETag at Conditional Requests
Ang ETags (Entity Tags) ay nagbibigay ng efficient na paraan para i-validate ang cached content nang hindi dinodownload ang buong response body.
Paano Gumagana ang ETags
- Initial Request — Client requests data, server responds with ETag
- Cache Storage — Client caches response with ETag
- Subsequent Request — Nagpapadala ang Client ng If-None-Match header na may naka-cache na ETag
- Pagpapatunay — Kung hindi nagbago ang data, magre-return ang server ng 304 Not Modified
- Bandwidth na Na-save — Walang response body na ipinadala, malaking tipid sa bandwidth
Pagpapatupad ng ETag
// Unang request
GET /v1/whales/btc HTTP/1.1
// Kasama sa Response ang ETag
HTTP/1.1 200 OK
ETag: "8a3b9c2d"
Cache-Control: public, max-age=300
Content-Type: application/json
{...response body...}
// Pag-expire ng cache, magpadala ng If-None-Match
GET /v1/whales/btc HTTP/1.1
If-None-Match: "8a3b9c2d"
// Kung hindi nagbago, magre-respond ang server ng 304
HTTP/1.1 304 Not Modified
ETag: "8a3b9c2d"
Cache-Control: public, max-age=300
// Walang body na ipinadala! Tipid sa bandwidth
Lakas ng ETag
Ang ETags ay maaaring strong o weak:
| Uri |
Format |
Use Case |
| Strong ETag |
"8a3b9c2d" |
Identikal sa bawat byte, gamitin para sa pagpapatunay |
| Weak ETag |
W/"8a3b9c2d" |
Semantically equivalent, para sa mga pagbabago sa display |
Mga Direktiba sa Cache Control
Ang pag-unawa sa mga direktiba ng Cache-Control ay nagbibigay-daan sa pagbuo ng optimal na caching strategies para sa iyong application.
Direktiba Reference
| Direktiba |
Kahulugan |
Halimbawa |
| max-age |
Segundong nananatiling fresh ang response |
max-age=300 |
| public |
Maaaring i-store at ibahagi ng cache |
public |
| private |
Cache para lamang sa recipient |
private |
| must-revalidate |
I-revalidate kapag stale |
must-revalidate |
| no-cache |
Dapat i-revalidate bago gamitin |
no-cache |
| no-store |
Huwag i-cache kahit kailan |
no-store |
| immutable |
Hindi nagbabago, i-cache magpakailanman |
immutable |
| s-maxage |
Tagal ng cache ng CDN |
s-maxage=3600 |
Mga Praktikal na Pattern ng Cache-Control
// Pattern 1: Browser cache, CDN para sa 1 oras
Cache-Control: public, max-age=300, s-maxage=3600
// Pattern 2: Per-user data, walang proxy cache
Cache-Control: private, max-age=1800
// Pattern 3: Laging fresh, laging i-check
Cache-Control: public, no-cache, must-revalidate
// Pattern 4: Immutable versioned asset
Cache-Control: public, max-age=31536000, immutable
Integrasyon ng CDN
Ang Smart Money API ay naghahatid ng mga response sa pamamagitan ng global CDN network ng Cloudflare, awtomatikong nagca-cache ng mga response sa mga edge location sa buong mundo para sa minimal na latency.
Paano Gumagana ang Smart Money CDN
- User Request — Ang request ay tumatama sa pinakamalapit na Cloudflare edge location
- Cache Check — Tinitignan ng edge kung naka-cache at fresh ang response
- Cache Hit — Kung naka-cache, i-serve agad na may <10ms latency
- Cache Miss — Kung hindi naka-cache, kunin mula sa origin server
- Store and Serve — I-cache ang response at i-deliver sa user
Cache Key Configuration
Gumagamit ang Cloudflare ng cache keys para matukoy ang mga naka-cache na response. Bilang default:
- Kasama ang request path at query parameters
- Karamihan sa mga headers ay hindi isinasama (para i-maximize ang cache hits)
- Hindi kasama ang Authorization headers (walang account leakage)
- Maaaring isama ang custom headers sa pamamagitan ng Vary header
Pag-purge ng CDN
Awtomatikong nagpu-purge ang Smart Money ng CDN cache kapag na-update ang data:
// I-purge ang specific na URL mula sa CDN
curl -X POST "https://api.smartmoneyapi.com/v1/cache/purge" \
-H "Authorization: Bearer token" \
-d '{
"urls": [
"https://api.smartmoneyapi.com/v1/whales/btc"
]
}'
Pagsukat ng CDN Performance
Tignan ang response headers para makita kung galing sa cache ang request:
// Cache hit mula sa CDN edge
CF-Cache-Status: HIT
CF-RAY: 8a9b7c6d5e4f3g2h
Age: 45 // segundo mula nang ma-cache
// Cache miss, kinuha mula sa origin
CF-Cache-Status: MISS
Age: 0
Client-Side Caching
Ipapatupad ang caching sa iyong application para mas mapababa ang mga API call at mapabuti ang responsiveness.
Browser Cache Implementation
// Gumawa ng cache storage
const cache = new Map();
async function fetchWithCache(url) {
// Suriin muna ang cache
const cached = cache.get(url);
if (cached && !isCacheExpired(cached)) {
return cached.data;
}
// Kumuha mula sa API
const response = await fetch(url);
const data = await response.json();
// Kunin ang tagal ng cache mula sa mga header
const cacheControl = response.headers
.get('cache-control');
const maxAge = parseMaxAge(cacheControl);
// I-store sa cache
cache.set(url, {
data,
expiry: Date.now() + (maxAge * 1000)
});
return data;
}
Service Worker Caching
Para sa offline support at advanced caching strategies, gumamit ng Service Workers:
// I-cache ang mga API response gamit ang Service Worker
self.addEventListener('fetch', (event) => {
if (event.request.url.includes('api.smartmoneyapi.com')) {
// Unahin ang network, pagkatapos ay cache kung sakali
event.respondWith(
fetch(event.request)
.then(response => {
// I-update ang cache gamit ang bagong response
caches.open('api-cache')
.then(cache => cache.put(
event.request, response.clone()));
return response;
})
.catch(() =>
caches.match(event.request))
);
}
});
Cache Busting Strategies
Minsan kailangan mong pilitin ang mga client na kumuha ng bagong data. Gamitin ang mga teknik na ito:
Version Parameter
Magdagdag ng version parameter para i-invalidate ang mga cache kapag nagbago ang data:
// Isama ang data version o timestamp
https://api.smartmoneyapi.com/v1/whales/btc?v=1709980800
// Kapag na-update ang data, dagdagan ang version
https://api.smartmoneyapi.com/v1/whales/btc?v=1709981000
// Bagong URL = bagong cache entry
Force Revalidation
I-override ang cache gamit ang Cache-Control: no-cache kapag kailangan mo ng fresh data:
// JavaScript: Pilitin ang fresh request
fetch(url, {
cache: 'no-cache', // Laging i-revalidate
headers: {
'Cache-Control': 'max-age=0'
}
});
Monitoring Cache Performance
Subaybayan ang cache hit rates at performance improvements para ma-validate ang iyong caching strategy.
Cache Metrics to Monitor
- Hit Rate — Porsyento ng mga request na naihatid mula sa cache (target: >70%)
- Response Time — Average latency (cached: <50ms, uncached: 100-300ms)
- Bandwidth Saved — Pagbawas sa data transfer
- Origin Load — Pagbawas ng request sa origin server
Analyzing Cache Headers
// Suriin ang response cache headers
async function analyzeCache(url) {
const response = await fetch(url);
return {
cacheControl: response.headers
.get('cache-control'),
etag: response.headers.get('etag'),
age: response.headers.get('age'),
cfStatus: response.headers
.get('cf-cache-status'),
contentLength:
response.headers.get('content-length')
};
}
Caching Best Practices
1. Igalang ang Response Headers
Laging igalang ang Cache-Control headers mula sa Smart Money API. Huwag i-cache ang content na may markang no-store o no-cache.
2. Mag-implement ng Conditional Requests
Magpadala ng If-None-Match (ETag) at If-Modified-Since headers kapag nagre-revalidate ng cached content. Mag-save ng bandwidth gamit ang 304 responses.
3. I-cache ng Naayon sa Uri ng Data
- Real-time data (funding rates): 1-5 second cache maximum
- Live signals (whale movement): 5-30 second cache
- Hourly data (OHLCV): 1 hour cache
- Historical data: 24-hour cache
- Static content: 7-day cache
4. Subaybayan ang Cache Effectiveness
Subaybayan ang hit rates at latency improvements. I-adjust ang TTLs base sa data freshness requirements at cache performance.
5. Gamitin ang Vary Headers nang Maingat
Ang Vary headers ay nagbabawas ng cache hits sa pamamagitan ng paggawa ng hiwalay na cache entries. Gamitin lamang ito kapag kinakailangan para sa iba't ibang antas ng authentication o parameters.
6. Mag-cache sa Maraming Layer
Mag-implement ng caching sa CDN, browser, at application levels. Bawat layer ay humaharang sa mga request bago umabot sa origin.
Optimize Your API Performance
Ang caching infrastructure ng Smart Money API ay nagsisiguro ng sub-100ms responses sa global scale. Mag-implement ng matalinong caching strategies para i-maximize ang performance at i-minimize ang costs.
Compare Plans
Ang lahat ng plans ay may kasamang full CDN caching. Ang mas mataas na tiers ay nagbibigay ng cache control at purging APIs.