spotify / spotify-web-api-ts-sdk

A Typescript SDK for the Spotify Web API with types for returned data.
Other
355 stars 69 forks source link

Does this library use ETags or any other caching mechanism behind the scenes? #68

Open EduardsE opened 1 year ago

EduardsE commented 1 year ago

Spotify documentation mentions "If the response contains an ETag, set the If-None-Match request header to the ETag value." to help with faster response times if no data has changed for requests response. Is it possible to set/receive this value with this library?

davidwhitney commented 1 year ago

It doesn't - however there's a really simple way to implement it so I'll try cook up a PR :)

davidwhitney commented 1 year ago

So, I did some experimentation with this over the weekend and put together an implementation of this and... well... honestly it's probably not worth the effort.

There are a grand total of absolutely no etags ever returned from the API, there's a bunch of cache-control headers with hints to cache results for ~2 minutes on 3-4 of the APIs (mostly search), and everything else explicitly returns cache-control never, or max-age of 0.

Feels like something that would help specifically only the case of revisiting a prior search result set in a 2-minute window :/

EduardsE commented 1 year ago

How about users playlists? I feel like that can be cached for significant amount of time since it doesn't change every day. And that endpoint returns etag. At least for my usecase, I'd basically have to skip using this lib for that endpoint and do a regular fetch + also would have to deal with token refresh on catch myself. Bit of a pain to workaround.