tags:

views:

357

answers:

1

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.

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.

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)

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.

+2  A: 

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.

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.

davogones