I'm trying to understand the caching aspect of DataLoader. I've got this inventories field which returns a bunch of inventories,
Field<ListGraphType<InventoryType>, IEnumerable<Inventory>>()
.Name("Inventories")
.Description("Get all inventories")
.ResolveAsync(context =>
{
var loader = accessor.Context.GetOrAddLoader("GetInventories", () => dataStore.GetInventories());
return loader.LoadAsync();
});
From the doc all I know is it will cache the result after the first time. But for subsequent requests, GetInventories still get executed and hits the database using entity framework.
Please let me know if I got my concepts wrong or am I missing anything? Thanks a lot.
It will be only "cached" for the duration of the query so that same data won't be resolved more than once during the graph execution.
@pekkah is correct. We wouldn鈥檛 want to make assumptions about caching data beyond a single execution. For example, you may need to return different data depending on the user making the request.
Got it. I was mixing it up with Etag related stuff. Thanks, @pekkah @johnrutherford for clearing it up.
Most helpful comment
It will be only "cached" for the duration of the query so that same data won't be resolved more than once during the graph execution.