All plans; cached routes retain their access requirements · Compare plans and subscribe
Reduce MadeOnSol API calls with safe backend caching
Cache identical MadeOnSol reads, coalesce concurrent requests and choose freshness policies without mixing chains, users or filters.
By MadeOnSol · Updated
Integration choice
Cache by the complete meaning of the request, then share in-flight reads for the same key. Separate fast-changing state from slower rankings. Choose freshness from what the screen needs rather than polling every panel at the same interval.
Before you start
- A backend-owned cache and a clear authorization boundary.
- A freshness target for each panel; the sample TTL is an application choice, not an API guarantee.
Implementation steps
- List the requests each screen makes, including chain, token, period, sort, pagination and selected intelligence modules.
- Build canonical keys within one account and permission scope. Preserve case for Solana addresses. Normalize Robinhood Chain hexadecimal addresses consistently without rewriting arbitrary identifiers.
- Coalesce concurrent identical reads. Cache only validated successful responses; do not turn an authentication error or failed refresh into an empty successful result.
- Give each dataset a freshness policy. Use streaming where supported, and bounded revalidation for snapshot-only data. Evict expired or least-recently-used entries to bound memory.
- Measure upstream reads and cache hit rate for the same workload before and after the change. Include cache expiry, reconnect and cold-start traffic.
Make a cache key describe the whole query
A leaderboard for seven days differs from one for another period, sort or filter. An intelligence request for snapshot,risk differs from one for snapshot alone. Include all result-affecting parameters and an authorization-scope identifier in your key; never use an API key itself as a loggable key.
Cache public-market responses across viewers only where the viewers are allowed to see the same data and your licence permits the display. Keep account information, watchlists and other user-specific responses in a private scope.
Separate cache age from data age
An entry fetched one second ago may describe an older source observation. Keep the local fetched-at time separate from the source timestamp or module as_of. Revalidating a cache entry does not automatically make its underlying market data fresh.
If you serve a last-known value while refreshing, retain its timestamp and quality internally. Do not overwrite a known value with a fabricated zero on an error. Select a product-specific expiry beyond which the value is no longer usable.
Bound both storage and refresh work
The example below coalesces reads within one process and bounds cached entries. Multiple backend replicas need a shared cache or an ownership strategy if they must coalesce across processes. Also cap concurrent upstream loads; cache size alone does not cap in-flight requests.
The current terms allow operational caching up to 24 hours for serving your application. Extended caching, bulk accumulation or a separately queryable dataset requires an Enterprise agreement. This permission is not a recommendation to display market prices from a 24-hour-old cache.
Code examples
Coalesce successful reads (standalone JavaScript)
// Node.js: local demonstration, no credentials or network calls.
// One process only. Add upstream concurrency limits separately.
function createReadCache({ ttlMs = 5000, maxEntries = 100, now = Date.now } = {}) {
if (!(ttlMs > 0) || !Number.isInteger(maxEntries) || maxEntries < 1) {
throw new Error("Invalid cache policy");
}
const cache = new Map();
const pending = new Map();
return async function read(key, load) {
const hit = cache.get(key);
if (hit && hit.until > now()) return structuredClone(hit.value);
cache.delete(key);
if (!pending.has(key)) {
const work = Promise.resolve().then(load).then(value => {
// The loader must validate the HTTP status and payload before returning.
const stored = structuredClone(value);
while (cache.size >= maxEntries) cache.delete(cache.keys().next().value);
cache.set(key, { value: stored, until: now() + ttlMs });
return stored;
}).finally(() => pending.delete(key));
pending.set(key, work);
}
return structuredClone(await pending.get(key));
};
}
const read = createReadCache();
// A scope identifier, never an API key. Keep Solana addresses case-sensitive.
const key = JSON.stringify(["account-a", "solana", "kol-leaderboard", "7d", "default-sort"]);
let upstreamReads = 0;
async function loadFixture() { upstreamReads += 1; return { rows: [] }; }
await Promise.all([read(key, loadFixture), read(key, loadFixture)]);
console.log({ upstreamReads }); // 1
Common mistakes and fixes
| Mistake | Recommended fix |
|---|---|
| Cache only by token address. | Include chain, account scope and every result-affecting query parameter. |
| Refresh every viewer independently at expiry. | Share in-flight work and stagger background refreshes. |
| Keep all responses forever. | Set retention and eviction policies consistent with the terms and your application needs. |
Verify your integration
Issue two simultaneous reads for the same key and verify one loader invocation. Change the chain or ranking period and verify a different result is fetched. Make the loader fail, retry, and confirm the failure was not stored as successful data. Test eviction and expiry.
Production checklist
- No cross-account or cross-chain cache collisions.
- Successful empty responses distinguished from failed requests.
- TTL, storage size and upstream concurrency bounded.
- Cache effectiveness measured under concurrent viewers.
Frequently asked questions
Does reducing response size reduce the number of REST calls?
Not by itself. Smaller responses can reduce bytes and processing, but request count drops only when you avoid or combine upstream requests.
Can one in-memory cache deduplicate reads across all replicas?
No. The example shares work within one process. Coordinate across replicas separately when needed.
