Memory Caching for ASP MVC apps running on Mono using Nginx Memory Caching for ASP MVC apps running on Mono using Nginx nginx nginx

Memory Caching for ASP MVC apps running on Mono using Nginx


Nginx caching and ASP.NET caching are two completely separate things. If you use [OutputCache] in your ASP.NET project, Nginx will not be aware of that. And vice versa, the proxy_cache_* directives in your nginx config will in no way affect the ASP.NET caching.

You should decide where to cache, either use nginx or use ASP.NET. If you want to use Nginx for caching, remove the [OutputCache] attribtues or disable output caching via web.config alltogether. Instead, create different locations for different cache zones in nginx like this:

# for your Home controller, assuming you use the /home/ routelocation /home/ {    proxy_set_header  Host             $http_host;    proxy_pass https://127.0.0.1:4430;    proxy_cache cache;    proxy_cache_valid 200 302 10m;    proxy_cache_valid 404 1m;}# for all other routeslocation / {    proxy_set_header  Host             $http_host;    proxy_pass https://127.0.0.1:4430;    # no proxy_cache here means no caching on the nginx side}

You can create complex location sections and use even regular expression to match your ASP.NET pathes/routes. See the nginx docs about that.

If you want to control caching from within ASP.NET, remove any proxy_cache* directives from the nginx configuration (like in the last location section in the example above) and use the regular ASP.NET caching directives like [OutputCache] directive.

I'd recommend using the nginx approach, as nginx is very fast and powerful, though requires a little reading at first. But if you get to know it, you can use its reverse proxy feature to create powerful web caches, not only for ASP.NET, but also for all other web application like ruby, node.js and so on.