Description
After using Teller a while, there is the potential to have lots of caches saved to the local device.
As an example, you have a DataSource
that retrieves the user profile of a user's social media account. If you simply call saveCache()
for every retrieval of every social media account, you could end up retrieving an infinite amount of cache. Teller at this does not provide a convenient way to delete cache that is obsolete. It's a manual process at this time.
Proposal: Teller tells your app what cache is (1) a certain age old or (2) the oldest of the cache collection so that you can delete your cache, easily.
Proposed API:
class UserProfileDataSource: DataSource {
var obsoleteAgeOfCache: Period = Period(unit: 5, component: .months)
// or...
var numberOfCacheResultsToKeep = 100
func deleteOldCache(_ requirements: Requirements) {
// Will be called for cache results that are > 5 months old or...
// will be called for cache that is the 101 oldest cache result or older.
}
}
You can specify neither, both, or one of the obsoleteAgeOfCache
or numberOfCacheResultsToKeep
properties. Teller will call deleteOldCache()
with requirements that meets at least 1 of the criteria. deleteOldCache()
does not allow throwing so it's recommended that a delete call error is recorded manually by the developer. Also, if the optional function deleteOldCache()
is not defined in the DataSource, Teller will skip the delete request and will be called again the next time the DataSource
is initialized.