Skip to content

emptyCache() does not work anymore #490

Closed

Description

@desmeit

I use 3.4.1.

I work with

await cacheManager.downloadFile(url);

and after that I get it from the cache with:

 final fileInfo = await cacheManager.getFileFromCache(
          url,
        );

I try to delete the cache with

await cacheManager.emptyCache();

It was working for a long time but now it is not working anymore.

flutter 3.29.3

Activity

  1. hafizramiz commented on Sep 7, 2025

    @hafizramiz

    I have got same issue
    void _clearCache() async{
    DefaultCacheManager().emptyCache();
    setState(() {
    fileStream = null;
    });
    }
    It is not remove cache

  2. colnaghijr commented on Sep 9, 2025

    @colnaghijr

    (running Flutter 3.32.8, flutter_cache_manager: ^3.4.1 on a MacOS)
    Just a quick check it seems like:

    cache_store.dart > class CacheStore
    _Future removeCachedFile
    successfully remove files from the _memCache

    though the absolute path of the file is wrong showing this:
    "/Users//Library/Containers//Data/filename.jpg"
    instead of
    "/Users//Library/Containers//Data/Library/Caches//filename.jpg"

    So line 187
    final file = io.File(cacheObject.relativePath);
    points to a non existing file
    and line 189
    if (file.existsSync())
    always fails.

    This creates a secondary defect as now files will be re-downloaded and duplicated in disk.

    For a potential fix, you might want to look into this PR: 3d1995f

  3. desmeit commented on Sep 10, 2025

    @desmeit
    Author

    @hafizramiz

    I have temporarily solved it manually until the plugin developer addresses the problem:

      Future<void> clearCachePhysically() async {
        final baseDir = await getTemporaryDirectory();
        final cacheDir = Directory('${baseDir.path}/libCachedImageData');
        if (await cacheDir.exists()) {
          await cacheDir.delete(recursive: true);
          print("Cache deleted.");
        }
      }
    
  4. diegogarciar commented on Dec 30, 2025

    @diegogarciar

    same issue here, _cleanupCache does not work because its using a relative path, it can't find the file on that directory when it clearly is, it is not using the appropriate path.

    Image
  5. diegogarciar commented on Dec 30, 2025

    @diegogarciar

    using the fileSystem instead of directly using File seems to have fixed the issue. createFile creates the File object not the actual file, so its fine to use it here.

    Image
  6. diegogarciar commented on Dec 30, 2025

    @diegogarciar

    seems the fix is already on main

  7. rickdijk commented on Jul 27, 2026

    @rickdijk
    Contributor

    This is merged into main and published in the latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions