跳到正文
Vercel Blog(vercel.com)· Agustin Falco·· 5 天前品質評分60

Vercel Blob 新增 TTL 自動刪除功能,簡化暫存資料管理

Vercel Blob now supports TTLs for automatic deletion

重點導讀

開發者常遇到暫存檔案需要手動刪除的麻煩,Vercel Blob 近期推出 TTL (Time‑to‑Live) 功能,允許在上傳時指定保留天數,系統會自動在到期時刪除。

  • 你只要在 put、copy 或 presign 時加入 ttlDays,回傳的 expiresAt 會告訴你何時會被清除。
  • CLI 也支援 --ttl-days 引數,並可用 set‑ttl 來延長或清除 TTL。這項功能不僅省去手動清理,還能在觀測面板追蹤 TTL 操作,讓資料管理更輕鬆。

AI 伴隨問答

自備 Key 深度分析

針對這篇報導有疑問?可直接點選快捷問題或向 AI 追問背景脈絡與技術細節:

正文

Vercel Blob can now delete blobs automatically. Pass ttlDays when you write a blob and it is deleted that many days after upload, from 1 to 730 days. The TTL counts from the blob's upload date.

Use TTLs for blobs you would otherwise delete yourself, such as session transcripts, exports, and temporary uploads.

ttlDays works on put(), copy(), putImage(), multipart uploads, and presigned upload URLs. Every write result and head() response now includes expiresAt, so you know when a blob is due for deletion.

import { put, setTtl } from '@vercel/blob';

// Delete this export 7 days after upload

const blob = await put('exports/report.csv', csv, {

access: 'private',

ttlDays: 7,

});

console.log(blob.expiresAt); // 2026-11-24T00:00:00.000Z

// Change your mind later: extend to 30 days, or clear it with null

await setTtl(blob.url, { ttlDays: 30 });

await setTtl(blob.url, { ttlDays: null });

setTtl() changes or removes the TTL of blobs you already have, one URL or up to 1,000 at a time, without re-uploading them.

In Vercel CLI 65.16.0 and later, pass --ttl-days to vercel blob put, put-image, copy or presign, and use vercel blob set-ttl on existing blobs.

vercel blob put report.csv --ttl-days 7

vercel blob set-ttl exports/a.csv exports/b.csv --ttl-days 30

vercel blob set-ttl exports/a.csv --clear-ttl

Setting a TTL costs one Advanced Operation per started 60 days, on top of the write. A 7-day TTL costs one, and the 730-day maximum costs 13. Clearing a TTL and the deletions themselves are free. You can track TTL operations in the Blob section of the Observability tab.

npm install @vercel/blob@2.9.0

Learn more in the Vercel Blob documentation.

來源: Vercel Blog (vercel.com)
開啟原文

讀者討論

理性交流 · 即時討論