Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Cache specific request, not whole service. #18

Open
yapryntsev opened this issue May 16, 2020 · 2 comments
Open

Cache specific request, not whole service. #18

yapryntsev opened this issue May 16, 2020 · 2 comments

Comments

@yapryntsev
Copy link

yapryntsev commented May 16, 2020

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?

@borchero
Copy link
Owner

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.

@yapryntsev
Copy link
Author

I suggest a simple solution in my PR #24

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants