graph-gophers / dataloader

Implementation of Facebook's DataLoader in Golang
MIT License
1.2k stars 75 forks source link

About caching in tutorial #97

Open hdlinh1808 opened 1 year ago

hdlinh1808 commented 1 year ago

Hi, Int the README.md, I found: This implementation contains a very basic cache that is intended only to be used for short lived DataLoaders (i.e. DataLoaders that only exist for the life of **an http request**). You may use your own implementation if you want. But when I test, I found that it cache for many requests. So I have the questions:

Thanks, Linh

vuon9 commented 1 year ago

Not sure if it can help, but you could consider to init the dataloader for each request then include it into the context of the request, rather than init the dataloader for the whole application. And in the last middleware of the request, you can call ClearAll for each dataloader to ensure you clean its memory.