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

Query available cache size before writing report to disk #592

Closed
wants to merge 4 commits into from

Conversation

fractalwrench
Copy link
Contributor

Goal

Currently FileStore writes an arbitrary 128 files to disk, which was a decision made in #97. When additional metadata is added to a report and the system is low on space, this may have the effect of making it more likely for the OS to reclaim space from our application.

Changeset

The changeset makes several alterations which will reduce the likelihood of our cached files being deleted by the OS:

  • Reduced max file count from 128 to 64. A typical error reports weigh around ~12Kb, which should fit into <1Mb storage if no additional metadata etc is added to a report
  • Cached context.cacheDir and the bugsnag-errors directory File as fields, reducing duplication
  • Moved discardOldFilesIfNeeded() into lock, reducing the potential for a Report serializing a cached Error to suffer a FileNotFoundException
  • Called getUsableSpace() to determine whether < 10Mb is available for use in the cache directory, and if so, delete old files.

Discussion

getCacheQuotaBytes() and getCacheSizeBytes() are available on API 26+ which would allow us to determine whether we are over the cache quota more precisely. However, the documentation warns that these calls can take several seconds to complete, and would not resolve any caching issues on older devices, leading to the approach in this PR.

See: https://developer.android.com/reference/android/os/storage/StorageManager

@fractalwrench
Copy link
Contributor Author

Closing for now, will reopen when we're confident about introducing this change.

@fractalwrench fractalwrench deleted the cache-size branch January 10, 2020 10:13
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

Successfully merging this pull request may close these issues.

1 participant