`title: IndexedDB 事务重试与指数退避策略``categories: Web 开发/前端/数据管理``keywords: IndexedDB,事务,重试,指数退避,稳定性``description: 针对事务失败与竞争场景设计指数退避与批量降级重试策略,提升前端持久化的稳定性。`重试实现async function withRetry(fn, max = 5) { let attempt = 0; let delay = 50; while (attempt < max) { try { return await fn(); } catch (e) { await new Promise(r => setTimeout(r, delay)); delay = Math.min(delay * 2, 1000); attempt++; } } throw new Error('retry failed'); } 批量降级大批次写入失败时降低每事务条数,避免长事务导致的失败与阻塞。

发表评论 取消回复