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

Clean up old caches #84

Open
levibostian opened this issue Jan 3, 2020 · 1 comment
Open

Clean up old caches #84

levibostian opened this issue Jan 3, 2020 · 1 comment
Labels
enhancement Would make an improvement in some way but is not a requirement such as a bug would be.

Comments

@levibostian
Copy link
Owner

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.

@levibostian levibostian added the enhancement Would make an improvement in some way but is not a requirement such as a bug would be. label Jan 3, 2020
@levibostian
Copy link
Owner Author

I encountered a use case today for this.

I wrote some migration code in my app where I needed to delete the old Teller cache data of 1 of my repositories so when the app installs the new update, just that 1 cache gets re-created.

I propose adding a clear() function to the Repository class that will (1) call deleteOldCache() on the data source to delete all of the old cache and (2) delete the Teller metadata associated with that repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Would make an improvement in some way but is not a requirement such as a bug would be.
Projects
None yet
Development

No branches or pull requests

1 participant