witness-org / witness

Your fitness witness!
1 stars 0 forks source link

Add Cache Layer To Avoid Redundant Network Calls #67

Open raffaelfoidl opened 2 years ago

raffaelfoidl commented 2 years ago

In GitLab by @11775820 on Feb 16, 2022, 21:44

Currently, we do not employ any means of caching. (Almost) every time a screen is visited, an HTTP request to the server is made. In many cases this is redundant. However, this feature is relatively complex and will take some time to plan, design and implement.

We have roughly the following (high-level) requirements:

Regarding the design, there are some aspects to consider:

Concerning the implementation, we basically have three options:

Implement the caching ourselves
A possible (very naive, rough and incomplete!) idea of the implementation could be:

This is quite simplistic approach and has not been thoroughly thought through yet. It might give an initial idea of the requirements, though.

Use a third-party library
For this second option we need to remember that our ultimate goal is to "save" network calls whenever an equivalent call (i.e. same parameters - HTTP method, URL, query parameters, payload etc.) has already been conducted before. Potentially fitting third-party libraries should be evaluated from that viewpoint.

Below is a list of possibly fitting libraries which have not been vetted rigorously. Instead, they ought to give a starting point for an investigation.

(keywords used to search for suitable libraries: cache, repository, memoization, lazy)

Use a hybrid approach
We could also build our own workflow for accessing the cache, but use a third-party library as data structure/data management solution. This might offer possibilities since there is probably no single library that satisfies all of our requirements. A cleanly self-designed caching layer with third-party data access might be a very well-maintainable solution.


All in all, we also need to keep in mind the memory footprint, levels of indirection and complexity introduced by our choice of implementation. We should strive for an optimal balance between them.