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.33k stars 456 forks source link

Request to support strongly typed keys efficiently or using generics #331

Open brianro opened 3 years ago

brianro commented 3 years ago

Love the library and use it all the time. Will you be introducing strongly typed keys, even if its for a subset of cache providers with limited support? Conversion of objects into string keys e.g. Type or Enum is a pretty expensive option when a strongly typed generic would be more efficient.

I understand the limitations of supporting multiple cache providers, but want to ask the question anyway to get your thoughts please.

Keep up the good work, B.

Jmerk523 commented 3 years ago

https://github.com/MichaCo/CacheManager/compare/dev...Jmerk523:generics_and_fixes This is by no means a solution, though it may turn into one. For now, it's a quick-and-dirty (very dirty) replacement of string keys with a generic type parameter. The changes so far only apply to Core and SystemRuntimeCaching as a proof-of-concept (for myself). There are certainly many bugs, e.g. wrong number of type parameters when reflecting generics. But, it didn't have any major complications, so realistically it could serve as an answer to the 'generic' question, and it may even be usable (for the core classes). I don't have any plans to bring this to any kind of completion, but the code is there so feel free to use it.

MichaCo commented 3 years ago

This might be something I'd consider in a future version, it would break the APIs though and would also require serialization on the key for distributed caches (which is why I didn't want to do that) But you can always serialize your object and use that as a key manually I guess