adobe / adobe/aepsdk-core-android

[CacheService] Auto delete cached items after expiry

Open
#649 0 comments 0 reactions 2 assignees Claimed by @siddique-adobe View on GitHub
defer enhancement
Dominant language
Kotlin
Stars
17
Forks
30
Avg merge
4h 12m
Merged PRs (30d)
4

Description

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.