System.Runtime.Caching.MemoryCache be persist for application across users in production

544 Views Asked by At

I have created a webapi2 app with angular2 application and angular service call to webapi , if webapi is got down , have to load the data from cache and the cache is expire after 20 minutes.

I am using Memory cache to cache the data in webapi. It is working fine in local application.

While moving to iis in production, it will be available for all the users or only available for the particular user.

It is a home page of the app, they don't have authentication. so everyone can see the page.

Else Which mechanism of cache will work in the above scenario?

Output cache -or Memory cache or any other caching strategy for webapi2.

1

There are 1 best solutions below

1
On

About Caching in webapi when you cache data in a web application, which get cached for that application i.e. which is kind of a common data public to all, ie) means when you cache that cache data is available to each request you make to your application, which in turn available to all users in the application.

One thing you can do is create cache type you want but, put [Authrized] attribute on the method which is providing cache data, it allowed to access cache to only those users who are logged in your application.

I have created and use a file-based Caching in WebAPI, advantage is , it gets expire when file gets modified so there is no query database till file get modified, Now question to when to modify file: I modify the file when there is insert, update, delete done on the data which I am caching.