kerego / tmdb_dart

The Movie DB API Client for Dart
MIT License
10 stars 7 forks source link

How to cache Configuration? #14

Open fdietze opened 4 years ago

fdietze commented 4 years ago

The tmdb API documentation states:

It is recommended you cache this data within your application and check for updates every few days.

https://developers.themoviedb.org/3/configuration/get-api-configuration

Maybe a method to set the configuration manually in the TmdbService is already enough?

kerego commented 4 years ago

Hi @fdietze,

TmdbService.InitConfiguration() currently returns a Future of type Configuration that you can write to persistent storage and then on the next startup of the app you can set the configuration directly using the configuration setter without having to call InitConfiguration().

It would have been good to have this done automatically as part of the library, however, it is not easily achievable, since persisting data usually requires platform-specific implementations. It could be done as separate packages built on top of this one that would add the functionality for specific use-cases like flutter/web etc. Another option could be passing something like 2 callbacks (write, read) to the tmbd service and let it handle caching, which should reduce the boilerplate.

On the short term plans though, It would probably be good to provide some code example for configuration caching (BTW, @fdietze most of the packages that are on dart pub have examples where you could check some simple scenarios implemented in the library to get a basic understanding on how to use it)

Perhaps it is also time to add some of the examples to the readme page, as most people expect to see some getting started info there.

fdietze commented 4 years ago

Ok, didn't see the configuration setter, that is good enough for me. :+1:

Another option could be passing something like 2 callbacks (write, read) to the tmbd service and let it handle caching, which should reduce the boilerplate.

Sounds like the simplest solution. But then I can also just use the setter myself...

On the short term plans though, It would probably be good to provide some code example for configuration caching (BTW, @fdietze most of the packages that are on dart pub have examples where you could check some simple scenarios implemented in the library to get a basic understanding on how to use it)

Wow, how could I have overlooked that? :facepalm: Since the readme was so simple I expected the library to be early stage and thought there was no documentation yet. I think a link from readme to the example would be enough for now.