Baseflow / Baseflow/flutter_cache_manager
Custom Age Threshold On Cache Objects Over Capacity
- 主要语言
- Dart
- 星标
- 809
- 派生
- 510
- 平均合并
- 6 分钟
- 30 天内合并 PR
- 1
描述
## 🏗 Enhancement Proposal
Allow configuring the age threshold used when cleaning up cache objects over capacity.
### Pitch
Currently, `getObjectsOverCapacity` uses a hardcoded `Duration(days: 1)` to filter which cached objects are eligible for removal during cleanup. This means objects touched within the last 24 hours are never removed, even if the cache exceeds its capacity.
This can be problematic in scenarios where:
- Apps have high cache turnover and need more aggressive cleanup (e.g., `Duration(hours: 6)`)
- Apps want to preserve recently accessed items for longer periods (e.g., `Duration(days: 7)`)
- The 1-day threshold doesn't align with the app's usage patterns
**Proposed solution:**
Add an optional `maxCapacityAgeFilterDuration` parameter to `Config` that allows developers to customize this threshold. The parameter defaults to `Duration(days: 1)` to maintain backward compatibility.
```dart
CacheManager(
Config(
'customCacheKey',
maxCapacityAgeFilterDuration: Duration(hours: 12), // Only remove items untouched for 12+ hours
),
);
```
This gives developers fine-grained control over cache eviction behavior without changing the default experience.
### Platforms affected (mark all that apply)
- [x] :iphone: iOS
- [x] :robot: Android
贡献指南
调研方向
定位 Config 和 getObjectsOverCapacity,然后追踪清理过程中硬编码的一天 Duration 在哪里被使用。添加可选的 Duration,同时保留一天的默认值,支持 12 小时等自定义值,并验证缓存清理仍然遵循配置的阈值。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- dart, flutter
- 领域
- mobile
- Issue 类型
- 功能
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100