Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从后台线程访问ASP.NET缓存_Asp.net_Multithreading_Asp.net Mvc 4_Caching_Httpcontext - Fatal编程技术网

从后台线程访问ASP.NET缓存

从后台线程访问ASP.NET缓存,asp.net,multithreading,asp.net-mvc-4,caching,httpcontext,Asp.net,Multithreading,Asp.net Mvc 4,Caching,Httpcontext,我正在编写一个ASP.NET MVC4应用程序,它在HttpContext.Current.Cache中存储一些安全数据。 然后,我建议使用写一个后台线程来将缓存中的内容与数据库同步。如果必须重新启动我的应用程序,这将提供一个恢复路径 因此,后台线程将执行以下操作: 1.) Add new security tokens to the database. 2.) Remove expired security tokens from the cache. 因此缓存需要支持后台线程的读写访问。据

我正在编写一个
ASP.NET MVC4
应用程序,它在
HttpContext.Current.Cache中存储一些安全数据。

然后,我建议使用写一个后台线程来将缓存中的内容与数据库同步。如果必须重新启动我的应用程序,这将提供一个恢复路径

因此,后台线程将执行以下操作:

1.) Add new security tokens to the database.
2.) Remove expired security tokens from the cache.
因此缓存需要支持后台线程的读写访问。据我所知,对缓存的访问是线程安全的,但是如果我从后台线程使用缓存,这种情况是否仍然存在

我知道,当我从后台线程访问缓存时,我需要调用:
System.Web.HttpRuntime
。缓存,因为没有当前请求

这个问题详述了类似的情况

感谢您的关注,感谢您的回复