graphql-dotnet / examples

Examples for GraphQL.NET
https://graphql-dotnet.github.io
MIT License
266 stars 186 forks source link

UseMemoryCache don't work #114

Closed Molochnikov closed 1 year ago

Molochnikov commented 1 year ago

Hello! Im using GraphQL 7.1.1 Memory Cache package and register it in DI like that: .UseMemoryCache(options => { options.SizeLimit = 1_000_000; options.SlidingExpiration = null; })

My sample resolve is:

 public class Query : ObjectGraphType<object>
    {
        public Query(IBusinessData data)
        {
            Name = "Query";
          Field<ListGraphType<EmailType>, IEnumerable<Emails>>("emails")
                .ResolveAsync(context => data.GetAutomappedValuesAsync<Emails>("Emails", "Emails", "", context.UserContext));

where GetAutomappedValuesAsync method is reading < 1MB data from web.

But every time i run query {emails {id}} GraphQL making web request instead of reading from cache.

What i have missed in configuring cache?

Shane32 commented 1 year ago

MemoryCache here just caches the GraphQL input string and its conversion to a GraphQL Document. It does not affect field resolvers.