async function analyzeCacheSegments(cache, options) {
  const keys = await cache.keys(options.keysPattern);
  const segments = /* @__PURE__ */ new Map();
  for (const key of keys) {
    if (options.filterKey && !options.filterKey(key)) continue;
    const segment = options.deriveSegment(key);
    if (!segment) continue;
    if (!segments.has(segment)) segments.set(segment, /* @__PURE__ */ new Set());
    segments.get(segment).add(key);
  }
  const results = [];
  for (const [segment, keySet] of segments.entries()) {
    results.push({
      segment,
      keys: Array.from(keySet).sort((a, b) => a.localeCompare(b))
    });
  }
  results.sort((a, b) => a.segment.localeCompare(b.segment));
  return results;
}
async function purgeCacheSegment(cache, options, segment) {
  const analyses = await analyzeCacheSegments(cache, options);
  const target = analyses.find((entry) => entry.segment === segment);
  if (!target) return { deleted: 0, keys: [] };
  let deleted = 0;
  for (const key of target.keys) {
    const removed = await cache.delete(key);
    if (removed) deleted += 1;
  }
  return { deleted, keys: target.keys };
}
export {
  analyzeCacheSegments,
  purgeCacheSegment
};
//# sourceMappingURL=segments.js.map
