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

Wrapper to handle multiple cache managers #265

Closed Miggleness closed 5 years ago

Miggleness commented 5 years ago

Continuing on question in issue #195, has there been any effort or an example of a wrapper that hides multiple typed CacheManagers into a single interface?

Miggleness commented 5 years ago

Nevermind, realized that ICache requires a generic parameter. ICacheManager<object> should be good enough to meet my needs.

I'm however curious as to the thinking behind the decision to make ICache strongly typed in itself. I find having to inject one CacheManager per type as per recommendation not a good pattern. Perhaps updating the architecture document with more than

Strongly typed caching brings many advantages over a object cache

MichaCo commented 5 years ago

There are pros and cons with typed vs non-typed. The current version of CacheManager is strongly typed all the way. You can use still use it as not typed by using T = object. I think that's flexible enough to satisfy all needs...

With DI, it is relatively easy to reuse a configuration and inject strongly typed cache manager instances for any type you request at injection time. I found a few disadvantage with that pattern though and a future version 2.0 might bring bigger changes to all that to improve usability and also re-usability of the underlying caches.

/closing this for now as its not really an issue. Keep an eye out for discussions in the future, I might post some things as issues when I've figured out a good design ^^

Miggleness commented 5 years ago

Thanks for the quick response, @MichaCo .

I can't think of a solution now without breaking your current API :P

I have to admin, I found your API lacking which led me to use other solutions (e.g. no generic GetOrAdd, no async). After switching ot CacheManager today, I'm surprised at how I quickly found ways around them.