@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
25 lines (23 loc) • 656 B
JavaScript
import { logger } from "./logger.js";
//#region src/cache.ts
/**
* Reads through a short cache. Never rejects: a failure is logged, reads as
* `null` and is not remembered, so the next request tries again.
*/
function readCached(what, ttlMs, current, store, load) {
const now = Date.now();
const cached = current();
if (cached !== void 0 && cached.expires > now) return cached.value;
const entry = {
expires: now + ttlMs,
value: load().catch((error) => {
logger.warn(`Could not read ${what}:`, error);
if (current() === entry) store(void 0);
return null;
})
};
store(entry);
return entry.value;
}
//#endregion
export { readCached };