简体   繁体   English

MVC Web应用程序中的应用程序变量刷新

[英]Application variable refresh in an mvc web app

I have an Application level variable that gets loaded from a database when the application starts. 我有一个应用程序级别的变量,该变量在应用程序启动时从数据库加载。 Now when accessing the variable, I check to see if it is not null. 现在,当访问变量时,我检查它是否不为null。 If it is not null I use it, if it is null I initialize it from the database, then use it. 如果不为空,则使用它;如果为空,则从数据库初始化它,然后使用它。

My question is how can I make sure that this variable is refreshed atleast once a day? 我的问题是如何确保每天至少刷新一次此变量? Is there something in .net or the MVC framework to help with this? .net或MVC框架中是否有什么可以帮助您解决此问题?

Does IIS unload an application if it has not accessed for a while? 如果一段时间未访问,IIS是否会卸载应用程序? If so then my variable would be refreshed each time the app is reloaded. 如果是这样,则每次重新加载应用程序时都会刷新我的变量。

Thanks 谢谢

You could use the class System.Web.Caching.Cache to store the variable with an expiration time. 您可以使用System.Web.Caching.Cache类来存储带有到期时间的变量。 That way once a day is up the value will be cleared and your code could reload it from the DB. 这样一来,每天便可以清除该值,并且您的代码可以从数据库中重新加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM