Last post Mar 16, 2017 04:49 PM by deepalgorithm
Mar 15, 2017 07:42 PMemail@example.com|LINK
I want to load cache when my web api application start. So in web api should i use memorycache or normal web cache can be used?
Mar 15, 2017 08:26 PM|deepalgorithm|LINK
Microsoft recommends using MemoryCache.
"When you develop new applications, we recommend that you use the MemoryCache class."
And here is another forum question about caching that I answered:
Mar 15, 2017 09:46 PMfirstname.lastname@example.org|LINK
Thanks for the reply. Suppose i have a web api which is in a distributed server. And if i have the memorycache mechanism implement in the application_start of the web api. Is that enough? or is there a Microsoft built in cache mechanism to control this?
Mar 16, 2017 05:14 AM|Chris Zhao|LINK
You could use Microsoft class for this called MemoryCache which resides in System.Runtime.Caching dll or different ways(e.g. a library like CacheCow ) to implement cache for Web API.
Mar 16, 2017 02:29 PM|deepalgorithm|LINK
See my answer below. If you are using a single server, then you can set up your cache in the application_start. Microsoft does not provide a mechanism to control this. Its up to you on how to implement it.
Otherwise, its not a good option for a distributed cache.
Mar 16, 2017 02:47 PM|deepalgorithm|LINK
Mar 16, 2017 02:52 PMemail@example.com|LINK
Thanks for the reply.How will it behave if the hosted web api is in distributed environment? Does Microsoft has any caching out of the box to handle distributed environment or doing cache in application_start is enough? I will be placing static data which
rarely changes in cache.
Mar 16, 2017 03:08 PM|deepalgorithm|LINK
MemoryCache is not a good choice if you have a distributed architecture as you will not be able to easily synchronize your caches. If you do have a distributed architecture and require something robust - then I recommend Redis along
with the .NET client developed by stackexchange.
If you have single web server then System.Runtime.Caching or the MemoryCache are sufficient.
Mar 16, 2017 04:21 PMfirstname.lastname@example.org|LINK
Is there any caching for distributed architecture out of box from Microsoft, if yes then any examples? Our client is little skeptic of not using 3rd part tools.
Mar 16, 2017 04:49 PM|deepalgorithm|LINK
Yes and no. It used to be
AppFabric, but Microsoft has or will be ending support for it soon. If you want Microsoft support, then you will have to use
Azure's redis provider. But redis can also be hosted on prem.
You should tell your client that Redis is probably the #1 distributed caching solution and is supported both in Azure and AWS. Another option is
I'm not sure I can give you any clearer guidance on this. Hopefully, I've answered all your questions.