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

[CacheService] Auto delete cached items after expiry #649

Open
prudrabhat opened this issue Apr 23, 2024 · 0 comments
Open

[CacheService] Auto delete cached items after expiry #649

prudrabhat opened this issue Apr 23, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@prudrabhat
Copy link
Contributor

Problem

Currently FileCacheService (the default CacheService implementation provided by core) allows components to cache items with an expiry. The cached item is only deleted when the expired item is requested again. The owner of the cached item is currently responsible for clearing these items from the cache on demand otherwise.
While this solution works, it can be improved to delete the content of the cache that have expired. This is especially useful for handling media/images in push notifications and in-app messages. (Imagine several in app message images being cached bloating the app cache)

Proposal

One possible solution is to run a task to delete all the expired content on every app launch. However, handling cache deletion from an SDK should be done in a way not to impact the app resource usage. In order to achieve a balance the following can be done:

  • Track the expiry of the cache timestamp with the earliest expiry - scheduledCleanupTimestamp
  • When FileCacheService is used to cache an item, check if its expiry is earlier than the currently stored scheduledCleanupTimestamp if yes, overwrite it. Otherwise do nothing
  • On each app launch, check scheduledCleanupTimestamp to see if the cleanup job has to be run and run the job.

Some things to take care of:

  • Simultaneous access to the cached item (CacheService.get() and delete job happening at once)

Platform and Version

Android 2.x or later.

@prudrabhat prudrabhat added the enhancement New feature or request label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants