我必须在.net控制台应用程序中创建缓存,然后如何在我的asp.net项目中访问控制台应用程序缓存。
问题描述:
我有一个大问题。
我必须创建缓存。网络控制台应用程序,然后如何在我的asp.net项目中访问控制台应用程序缓存。我的缓存在控制台应用程序中每一小时更新一次。我想在我的asp.net web应用程序中访问控制台应用程序缓存。
请帮助我。
谢谢........
Hi,
I have a big problem.
I have to created cache in .net console application, then how can I access console application cache in my asp.net project. My cache updated in every one hour in console application. I want to access console application cache in my asp.net web application.
Please help me.
Thank you........
答
嗨NagaRaju
在我看来将你的逻辑从你的控制台应用程序转移到一个可以被控制台和web应用程序访问的单独的类库中是一种很好的做法。
我用的东西沿着我的存储库中的代码行缓存静态数据。存储库位于自己的类库中,可以由Web应用程序,控制台应用程序,Windows应用程序等使用。在下面的示例中,我使用的是System.Runtime.Caching库中的类...
Hi NagaRaju
In my opinion it would be good practice to move your logic off your console application and into a separate class library that can be accessed by both the console and web apps.
I use something along the lines of the code below in my repositories to cache static data. The repositories are in their own class library and can be used by a web app, console app, windows app, etc. In the example below I'm using the classes from the System.Runtime.Caching library...
public class CacheManager
{
public static object GetCachedItem(string key)
{
return MemoryCache.Default[key];
}
public static void AddItem(string key, object item)
{
var expiration = int.Parse(ConfigurationManager.AppSettings[key]);
var policy = new CacheItemPolicy
{
Priority = CacheItemPriority.NotRemovable,
AbsoluteExpiration = DateTimeOffset.Now.AddHours(expiration)
};
MemoryCache.Default.Set(key, item, policy);
}
}
希望这有帮助
Hope this helps