In-memory proxy for caching data #1844
-
Hello, Let's say there is a screen with list of profiles, each time user goes to this screen, the app will show profiles from cache (via db call using drift), then it will actualise the data from server and update cache if anything changes. So far so good, but when the user goes to the aforementioned screen, there is a split second when the data from the db is still fetching and the page is empty. The gut reaction I have is to pre-load this data on the application start up, so that it will fetch the data from the memory instead of the database. That is basically where my train of thought ends - I'm not sure what is the best way to approach this issue. My initial idea and the reason why I’m here is to make a proxy layer between the database and application, which will manage the in-memory caching logic. But it occurred to me that drift might already have some solution, or there is some similar discussion on this point, so why not ask the community/developers of drift :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks! ❤️
This isn't what you asked for, but first a general note: For performance reasons alone, this shouldn't be necessary. sqlite3 will cache parts of your database in-memory as well. So for databases that aren't too large, you'll get most drift/sqlite3 queries answered from memory either way.
Are you using a query stream for this? I assume that this is mostly due to the data being fetched asynchronously (e.g. if you use a If you reach the screen with all the profiles through a tap, you could wait for the first snapshot before pushing the route. In your Drift has no builtin integration for caching. You could keep the stream for this query active from the start of your app and cache the results yourself. Bu be aware that having too many query streams active when you don't need them may also slow your app down since drift will fetch results again for every potential update. |
Beta Was this translation helpful? Give feedback.
Thanks! ❤️
This isn't what you asked for, but first a general note: For performance reasons alone, this shouldn't be necessary. sqlite3 will cache parts of your database in-memory as well. So for databases that aren't too large, you'll get most drift/sqlite3 queries answered from memory either way.