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?
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.
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.
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.
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.
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.
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.
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
NCache.
I'm not sure I can give you any clearer guidance on this. Hopefully, I've answered all your questions.
None
0 Points
9 Posts
Caching in Webapi
Mar 15, 2017 07:42 PM|manishev85@gmail.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?
Participant
1060 Points
320 Posts
Re: Caching in Webapi
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."
More here:
https://msdn.microsoft.com/en-us/library/dd997357.aspx
And here is another forum question about caching that I answered:
https://forums.asp.net/p/2100077/6068942.aspx
None
0 Points
9 Posts
Re: Caching in Webapi
Mar 15, 2017 09:46 PM|manishev85@gmail.com|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?
All-Star
17602 Points
3510 Posts
Re: Caching in Webapi
Mar 16, 2017 05:14 AM|Chris Zhao|LINK
Hi Manishev85,
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.
reference:
https://code.msdn.microsoft.com/Caching-In-Web-API-cb40be30
https://damienbod.com/2014/05/18/exploring-web-api-2-caching/
http://blog.developers.ba/simple-way-implement-caching-asp-net-web-api/
Best Regards,
Chris
Participant
1060 Points
320 Posts
Re: Caching in Webapi
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.
Participant
1060 Points
320 Posts
Re: Caching in Webapi
Mar 16, 2017 02:47 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.
None
0 Points
9 Posts
Re: Caching in Webapi
Mar 16, 2017 02:52 PM|manishev85@gmail.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.
Participant
1060 Points
320 Posts
Re: Caching in Webapi
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.
None
0 Points
9 Posts
Re: Caching in Webapi
Mar 16, 2017 04:21 PM|manishev85@gmail.com|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.
Participant
1060 Points
320 Posts
Re: Caching in Webapi
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 NCache.
I'm not sure I can give you any clearer guidance on this. Hopefully, I've answered all your questions.