Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

can not delete cache file

未关闭
#472 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
dart, flutter
领域
tooling

调研方向

首先跟踪 issue 中所示的 cacheObject.relativePath 删除路径和 ExternalStorageFileSystem.createFile 实现。检查文件路径是如何生成和使用的,然后验证删除缓存对象时会删除外部存储中的相应文件,同时不会破坏现有的缺失文件处理逻辑。当此文件系统创建的缓存文件可以成功删除时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

    if (toRemove.contains(cacheObject.id)) return;

    toRemove.add(cacheObject.id!);
    if (_memCache.containsKey(cacheObject.key)) {
      _memCache.remove(cacheObject.key);
    }
    if (_futureCache.containsKey(cacheObject.key)) {
      await _futureCache.remove(cacheObject.key);
    }
    final file = io.File(cacheObject.relativePath);

    if (file.existsSync()) {
      try {
        await file.delete();
        // ignore: unused_catch_clause
      } on PathNotFoundException catch (e) {
        // File has already been deleted. Do nothing #184
      }
    }

cacheObject.relativePath is not real abs file path ,delete file can not work
class CustomCacheManager { static const key = 'tsl'; static final fileSystem = ExternalStorageFileSystem(key); static CacheManager instance = CacheManager( Config(key, stalePeriod: const Duration(days: 30), maxNrOfCacheObjects: 999999999, fileSystem: fileSystem), ); }
`
class ExternalStorageFileSystem implements FileSystem {
final Future _fileDir;
final String _cacheKey;

ExternalStorageFileSystem(this._cacheKey)
: _fileDir = createDirectory(_cacheKey);

static Future createDirectory(String key) async {
final baseDir = await getExternalStorageDirectory();
final path = p.join(baseDir!.path, key);

const fs = LocalFileSystem();
final directory = fs.directory(path);
await directory.create(recursive: true);
return directory;

}

@override
Future createFile(String name) async {
final directory = await _fileDir;
if (!(await directory.exists())) {
await createDirectory(_cacheKey);
}
return directory.childFile(name);
}

void emptyCache() async {
final directory = await _fileDir;
if (await directory.exists()) {
await directory.delete(recursive: true);
}
}
}
`

主要语言
Dart
星标
812
派生
511
平均合并
28 分钟
30 天内合并 PR
12

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Baseflow/flutter_cache_manager 的其他 Issue

查看 Baseflow/flutter_cache_manager 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。