clragon / e1547

A sophisticated e621 browser
https://e1547.clynamic.net/
GNU General Public License v3.0
209 stars 16 forks source link

Caching with dio #51

Closed clragon closed 2 years ago

clragon commented 2 years ago

We should use dio_http_cache to cache network requests and make the app experience more fluid.

An idea is to provide a default cache for 5 minutes for each request, with some exceptions.

clragon commented 2 years ago

as it stands, the caching with dio is mostly done. We have created a wrapper for dio that handles all the caching and the key creating.

There is one issue to consider for the future: Certain caches need to be cleared when the user executes an action.

We have written a function that provides this, but there is no sensible way of clearing an overall post collection from a single post when that post is favorited, for example, because it is unclear what search that post belongs to.

Clearing of searches would need to be done by data controllers? This would decrease overall code cohesion.

As of now, if a user favorites a post and reopens the search within 5 minutes, that post will appear to be not favorited.

clragon commented 2 years ago

with the new code in the data controllers that allows us to update items with force (refreshing the cache), caching is now fully operational. this means, when an item is updated, for example favorited, then the controller will silently clear the cache and repopulate it. the controller does not update its data, but if the user reopens this screen, the data will be refreshed.

the reason for not updating the controller data is shift in posts or other similar interruptances which we do not want to happen when executing actions on a post.

one thing to consider for the future might be to debounce force requests, as a user might upvote and favorite etc a post in quick succession, leading to multiple refresh requests.