Closed Dartlexx closed 5 years ago
As I found out, it's extremely hard to work with KCallables in such solution, as each parametrized call is converted into generated class with contains a field with parameters. So that it makes a nightmare to call them via reflection.
So I suggest another approach now:
interface DataProvider { suspend fun getData(): Data fun parametrizeKey(baseKey: String): String = baseKey }
interface CacheProviders {
@ProviderKey("TestKey", EntryClass(Data::class))
@LifeTime(value = 1L, unit = TimeUnit.MINUTES)
@Expirable
@UseIfExpired
suspend fun getData(dataProvider: DataProvider): Data
}
Right now, CoroutineCache doesn't support caching similar data requests with different parameters.
Lets say, we are caching a search request for Products with string parameter 'productName'. Any such request would be cached under the same key, that was set in @ProviderKey("ProductsSearch"). So we may encounter following situation:
I suggest to add another lambda into getData signature, that will be written by CoroutinesCache user and that will do required modifications to @ProviderKey based on input parameters. Example:
If such modifier is present, than base key will be modified according to provided lambda. Default implementation can be created, that takes a list of Objects to calculate overall hash of parameters.