FilledStacks / provider_architecture

A set of widgets to help with the implementation of the Provider architecture as shown by FilledStacks
86 stars 15 forks source link

Caching the Model Data #17

Open Amerr opened 4 years ago

Amerr commented 4 years ago

First of all thanks for provider_architecture in reducing the pain of building up a large and maintainable app

After reading couple of issues and blog posts. Registering viewModel as registerLazySingleton rather than registerFactory to avoid multiple requests in API or any data layer. I want to know how to achieve caching in this architecture?

But I am interested in your view and how do you approach it. It would be nice if you are able to explain it with a real use case.

FilledStacks commented 4 years ago

Hi @Amerr I handle all my caching in the services. The viewmodel would only make multiple requests if you're requesting data in the constructor. Which you probably shouldn't. My services handle anything like that. OrderService makes a request, keeps the orders locally or in a db, when requesting it again I first serve from the DB and then go to the API and fetch that.