缓存在控制台应用程序 [英] Caching in a console application

查看:164
本文介绍了缓存在控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要缓存一个通用的列表,所以我不必须多次查询DATABSE。在Web应用程序,我只能将其添加到 httpcontext.current.cache 。什么是缓存在控制台应用程序对象的正确方法?

I need to cache a generic list so I dont have to query the databse multiple times. In a web application I would just add it to the httpcontext.current.cache . What is the proper way to cache objects in console applications?

推荐答案

请其为包含类的实例成员。在Web应用程序,你不能这样做,因为页面类的对象在每次请求重新

Keep it as instance member of the containing class. In web app you can't do this since page class's object is recreated on every request.

不过.NET 4.0还具有的的MemoryCache 为此类。

However .NET 4.0 also has MemoryCache class for this purpose.

这篇关于缓存在控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆