MichaCo / CacheManager

CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
http://cachemanager.michaco.net
Apache License 2.0
2.34k stars 457 forks source link

Generic Type Keys #235

Closed mansoor945 closed 6 years ago

mansoor945 commented 6 years ago

Hi @MichaCo,

I have started using your library and it is working great for me.

Right now for Dictionary, Memory Handle and all other handles, only string is supported as keys.

If you can support Generic Type Keys, it would be great.

Usage

I have an object which identifies unique request which is made to database server. I want to cache the response of the database query, and for that I want the key to be set as that object.

Sample Code

I am looking for something like the below signature: void Put<T1>(T1 key, TCacheValue value);

MichaCo commented 6 years ago

Hi @mansoor945 thanks for the feedback! There are currently no plans to add complex objects as keys. That was by design, primarily because distributed caches use strings as keys, obviously. To use complex objects, you can/have to implement the transformation to a string yourself. Either override ToString or serialize your key, whatever. It is not really hard to do, that's why I never saw the point of adding and better keep it simple...