Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong calculation of cache size #81

Open
bimusiek opened this issue May 22, 2024 · 0 comments
Open

Wrong calculation of cache size #81

bimusiek opened this issue May 22, 2024 · 0 comments

Comments

@bimusiek
Copy link

I think the calculation of cache size is wrong. When testing, it returned size of a directory without content.
Proper way would be:

const dirSize = async (dir: string) => {
  const files = await FileSystem.statDir(dir);

  const paths = files.map(async (file): Promise<number> => {
    const filePath = `${mainCacheDir}${file.path}`;

    if (file.type === 'directory') {
      return dirSize(filePath);
    }

    return file.size;
  });

  return (await Promise.all(paths)).flat(Infinity).reduce((i, size) => i + size, 0);
};
export async function getCacheSize(): Promise<number> {
  return dirSize(mainCacheDir);
}

I know it is used only to validate if cache dir exists, but in my case I am using it to show the button in the app with cache size and ability to clear cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant