Graphql-dotnet: How caching works with DataLoader?

Created on 28 May 2018  路  3Comments  路  Source: graphql-dotnet/graphql-dotnet

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.

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dimortizp picture dimortizp  路  3Comments

damithashyamantha picture damithashyamantha  路  4Comments

thivy picture thivy  路  3Comments

tcetin picture tcetin  路  3Comments

Historyman picture Historyman  路  3Comments