0

I have one class where I'm holding information in Concurrent Dictionary for 30 minutes. That class should be initialized as Singleton and not as Transient right? To my understanding if it is Transient than with every request it will create new instance and cache would get wiped.

Can somebody confirm this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
earthy
  • 1
  • 3
  • This question and topic has been already asked and answered. See this topic: https://stackoverflow.com/a/38139500/5121136 – Attila Molnar Jun 11 '21 at 18:51
  • 1
    Have you looked at `MemoryCache`? https://learn.microsoft.com/en-us/dotnet/api/system.runtime.caching.memorycache – Flydog57 Jun 11 '21 at 19:13
  • It is not possible to answer as we don't know if that cache should be shared for whole app or specific per services. Indeed you correctly identified that "scoped" is unlikely correct choice since HTTP requests handling should not really take 30+ minutes, but choice between singleton and transient is completely dependent on you application needs/design and more information need to be [edit] in to make the question answerable. – Alexei Levenkov Jun 11 '21 at 19:26
  • `Can somebody confirm this?` What happened when you tried it? – mjwills Jun 11 '21 at 21:25
  • Cache is for whole app and basically idea is that with POST requests information is being saved there for 30min and than should be available during this time to be retrieved with GET requests. Information being saved there is very basic. I will be able to try the singleton in two days(not home). Also would using Memory cache make more sense for my case performance wise? – earthy Jun 12 '21 at 10:44

0 Answers0