I want to build a scrolling image collection, and I have a few ideas about how to go about it. I've gone down a few incorrect paths and had to backtrack, so I thought I'd open up my current plan in case someone could give me the benefit of their experience to advise me where I might be going wrong.
Loading
Images are stored on the SQL database in a binary format, accessed through a DbContext and stored in DbSets. I've seperated out my objects that use the images from the images themselves. This allows me to create a light load and a full load, where the light load loads all of the info except for the heavy portions (in this case that image binary data). This allows the image showcase to populate the grid very quickly, and then go through each image in the background loading them fully.
This was a workaround because I couldn't find or figure out a solid component for lazy loading / virtual scrolling / Intersecion Observer.
I don't want the user to have to re-load all of these images once they've been loaded once. I would have thought that the dbset's would store the data once it was loaded, and return it instantly for all other queries after that point. But it doesn't seem to be the case. As load times seem to be present each time.
Content is grabbed like this
using (var context = new SampleContext())
{
var author = context.Authors.ToList();
}
My question is, should I store the result of this query in the Controller itself?
Or a state object?
Or am I misunderstanding something about dbSet and should be able to retrieve them from memory after they've been loaded once?