← Files RivetARCHIVED FILE
node_modules/drizzle-orm/cache/core/cache.cjs
1.72 KB · Nov 5, 2026 · 12:09 UTC
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
let __entity_ts = require("../../entity.cjs");
//#region src/cache/core/cache.ts
var Cache = class {
static [__entity_ts.entityKind] = "Cache";
};
var NoopCache = class extends Cache {
static [__entity_ts.entityKind] = "NoopCache";
strategy() {
return "all";
}
async get(_key) {}
async put(_hashedQuery, _response, _tables, _config) {}
async onMutate(_params) {}
};
const strategyFor = async (query, params, queryMetadata, withCacheConfig) => {
if (!queryMetadata) return { type: "skip" };
const { type, tables } = queryMetadata;
if ((type === "insert" || type === "update" || type === "delete") && tables.length > 0) return {
type: "invalidate",
tables
};
if (!withCacheConfig) return { type: "skip" };
if (!withCacheConfig.enabled) return { type: "skip" };
if (type === "select") return {
type: "try",
key: withCacheConfig.tag ?? await hashQuery(query, params),
isTag: typeof withCacheConfig.tag !== "undefined",
autoInvalidate: withCacheConfig.autoInvalidate,
tables: queryMetadata.tables,
config: withCacheConfig.config
};
return { type: "skip" };
};
async function hashQuery(sql, params) {
const dataToHash = `${sql}-${JSON.stringify(params, (_, v) => typeof v === "bigint" ? `${v}n` : v)}`;
const data = new TextEncoder().encode(dataToHash);
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
return [...new Uint8Array(hashBuffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
}
//#endregion
exports.Cache = Cache;
exports.NoopCache = NoopCache;
exports.hashQuery = hashQuery;
exports.strategyFor = strategyFor;
//# sourceMappingURL=cache.cjs.mapSHA-256: 31d4b48e6a8403b1df57c39187082ad11e7b9849dfc971f2e897f58a72e8b2bb