Add an IndexedDB cache to AJAX calls with Scroller
Add an IndexedDB cache to AJAX calls with Scroller
I've been playing around with using datatables with data that's loaded into IndexedDB, which gives almost the speed of an in-memory table with the scope of AJAX-driven tables. Of course, it requires loading the data, and possibly refreshing it, etc. But it also allows completely off-line datatables (with PWA you can even load all the libraries, etc.)
My next step is to do a hybrid of using the IndexedDB (actually, I use dexie, a wrapper that makes IndexedDB much easier to use), and when the ajax method of datatables is called, it first looks to see if I already have the data and if not just loads the missing rows (and eventually check a cache time). It occurred to me that the datatables library and scroller already do this to some extent -- a certain range of rows, larger than the visible area, are in memory, and only when the user scrolls outside of that area is the ajax method called to fetch more rows.
So this might be a cool feature for datatables to integrate directly. A lot of data is already stored in memory with the rowId, dexie would also allow that data to be indexed/accessed by some unique code.
While it introduces another dependency, dexie is worth looking into as a way to basically have a disk-based cache which could make scroller considerably faster.
When the next release of scroller comes out I'll post my prototype of the dexie-based datatable browser.
Replies
I've used dexie before as well and I do like it.
I'm not quite clear on what specific feature you are referring to I'm afraid? As you say, Scroller does that so some extent already (this part of the blog post introducing Scroller explains my thinking there).
Do you mean always running the request for more data through Dexie? I'm afraid that would be a non-starter for me. I want to keep dependencies and file size as low as I reasonably can. There should be APIs and methods to allow that though.
Allan
Yeah, it's was in the end of year brainstorming. I can see why you'd want to minimize dependencies. My idea was to use dexie as a cache, when the scroller moves outside of the rows already in memory, before making the ajax callback check dexie first.
I'm with you - thanks for the clarification. Yup, if that is something that someone needs, then they could readily implement with an
ajax
function override I think.Allan