/** Wrap a computation with tag-based caching. */
export async function cached(adapter, key, tags, ttl, fn) {
    const existing = await adapter.get(key);
    if (existing)
        return existing.value;
    const value = await fn();
    await adapter.set(key, { value, tags, expiresAt: Date.now() + ttl }, ttl);
    return value;
}
/** Invalidate all cache entries associated with a tag. */
export async function revalidateTag(adapter, tag) {
    await adapter.invalidateTag(tag);
}
/** Build a cache key from a collection, operation, and parameters. */
export function buildCacheKey(collection, operation, params) {
    const base = `actuate:${collection}:${operation}`;
    if (!params)
        return base;
    const sorted = Object.entries(params)
        .sort(([a], [b]) => a.localeCompare(b))
        .map(([k, v]) => `${k}=${JSON.stringify(v)}`)
        .join('&');
    return `${base}:${sorted}`;
}
/** Get the standard cache tags for a document. */
export function getDocumentCacheTags(collection, documentId) {
    const tags = [`collection:${collection}`];
    if (documentId)
        tags.push(`doc:${documentId}`);
    return tags;
}
//# sourceMappingURL=index.js.map