SandroHc/reactive-jikan

Plan for ETag / If-None-Match usage

zakaoai opened this issue · 3 comments

Hello, I'm currently using your lib and would thank you for this amazing job you done.
I also want to know if you plan to implement cache gestion with Etag / If-None-Match Headers ?

It would be doable, but I am not sure about the usefulness of that kind of caching. If we have to cache the results on our side, might as well not even make the HTTP request at all. Jikan has some well defined caching times that we could use to on our side to expire stale results.

The external library Caffeine could be used for managing the cache but I am not sure if adding a new dependency is the right approach or right direction for this project. We could also provide a cache abstraction and let the end-user decide the caching library he wants to use, but I wanted to keep this library easy to use.

Well in fact, yes if we implement our own cache base we can use the 3 items that we get from api response :
requestHash
requestCacheExpiry

But to refresh our cache expiry using this 2 header can be usefull. Well, I don't know how they define their request limit and cached request.

I don't think you need to add some external lib too. But why not for the cache abstraction 🤔

Hey, @zakaoai, sorry for the long wait. Caching is now enabled by default starting on v2.0.0.

You can create your own implementation via:

JikanCache customCache = new JikanCache() {
	private final Map<String, Object> cache = new HashMap<>();

	@Override
	public void put(String key, Object value, OffsetDateTime expires) {
		cache.put(key, value);
	}

	@Override
	public Optional<Object> get(String key) {
		return Optional.ofNullable(cache.get(key));
	}
};

Jikan jikan = new JikanBuilder().cache(customCache).build();

I'll close this issue for now. Please reopen in case you have any further queries. :)