Cache specific request, not whole service.
yapryntsev opened this issue · comments
I think that is really a common situation, when you need to cache result of a specific request that ideological belongs to some HttpService
. But now all requests that belong to the service with cache hook are caching.
For example, I have a service that provides auth methods and caching ableProfile
request is a good idea, but caching isLogined
request looks pretty weird. I really don't want to create HttpService
for each request I need to cache.
Do you plan implement that sort of functionality or did I miss something and there is some elegant way to do it?
For the time being, I would introduce the following (empty) protocol:
protocol CachableJsonRequest: JsonRequest { }
Then, in your hook, you could implement the onSchedule
and onSuccess
methods and dynamically check for the type of the request, i.e.:
guard request is CachableJsonRequest else {
return nil
}
I know this is not ideal (as it also requires you to implement your own CachingServiceHook
) -- let me know if you got any ideas.
I suggest a simple solution in my PR #24