Using HttpContext.Current.Application to store simple data

后端 未结 5 1056
旧时难觅i
旧时难觅i 2020-12-09 19:02

I want to store a small list of a simple object (containing three strings) in my ASP.NET MVC application. The list is loaded from the database and it is updated rarely by ed

5条回答
  •  轮回少年
    2020-12-09 19:23

    If you're deploying to a single web server the approach would work. Consider the Cache object for this as it provides more options for expiration if you need such functionality. (See a comparison, albeit an aged one, here.)

    If you're ever going to deploy to a web server farm or equivalent you should use memcached or another web farm friendly caching mechanism. Both the Application and Cache objects only typically exist in a single server context; if your user could be hitting multiple web servers during their session (and the cache needs to be identical) you'll need a shared cache that can be seen from each of the potential web servers.

    Regardless of which path you take you will need to invalidate/reload your cache whenever the underlying data changes, which is custom code that varies by app.

    This approach works well and can speed things considerably but it's a bit more work than you may realize at first glance...

提交回复
热议问题