c# - MemoryCache over Threads -


i'm investigating code has cache layer @ bottom level uses memorycache class. c# windows service app not web/iis. there section of code spawns off number of threads in creates , executes code in poc perform calculations. these stored in above mentioned cache layer. been seen looks cached values seem getting stored per thread , not @ apication level. thought memorycache singleton sit out side of individual threads.

can confirm behaviour expected?

many comments.

a memorycache thread-safe there no reason assume it's singleton. if want different threads access same memorycache instance need give them reference same instance (either singleton (really bad) static (still bad) or through argument passing dependency injection (good)).

the simple way (which use global state) access default memory cache:

var cache = memorycache.default; // not idea , harder test, works 

you can find specific docs here. make sure configure in app/web.config file.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -