通用缓存机制.NET [英] Generic Cache mechanism for .NET

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

问题描述

我有一个类库,它有一个Person类。 Person类包括国家或地区名称和国家code的属性。乡村code是存储在Person表中的值。该国家或地区名称是从所附的查找表中检索。

I've got a class library which has a Person class. The Person class includes a property for CountryName and CountryCode. The CountryCode is the value stored in the Person table. The CountryName is retrieved from an accompanying lookup table.

由于国家或地区名称和国家code之间的映射是不太可能永远改变,我觉得用缓存为Person业务对象中查找。

Because the mapping between CountryName and CountryCode is not likely to ever change, I feel comfortable using caching for the lookup within the Person business object.

我的类库将用于ASP.NET站点,以及在未来的控制台和Windows应用程序。 什么是正确的机制来实现这种类型的通用缓存?(注意小G,而不是.NET泛型)

My class library will be used for ASP.NET sites as well as Console and Windows apps in the future. What is the proper mechanism for implementing this type of generic caching? (note little "g", not .NET Generics)

您可能会认为,缓存应该在不同的层来完成,但我仍然认为在任何类型的.NET项目工程缓存机制有可能受益。

You might argue that the caching should be done at a different layer, but I'd still likely benefit from a caching mechanism that works in any type of .NET project.

推荐答案

我使用的企业库缓存应用程序块缓存在我的应用程序的每一层。在ASP.NET中,我用的是内置的ASP.NET缓存。

I use the Enterprise Library Caching Application Block to cache on every tier of my application. In ASP.NET, I use the built-in ASP.NET cache.

我真的建议你创建一个实现无关的缓存接口,一个单独的程序。这样,以后你可以交换的实现,如果你需要,而无需改变code在jillion地方。使用依赖注入框架,比如统一这也将让您使用相同的缓存接口ASP.NET和你的code休息,但换出的实际执行情况。

I would actually recommend you create a separate assembly with an implementation agnostic caching interface. This way you can swap implementations later if you need to without needing to change code in a jillion places. This will also allow you to use the same caching interface in ASP.NET and the rest of your code, but swap out the actual implementation using a dependency injection framework like Unity.

这篇关于通用缓存机制.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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