alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.72k stars 159 forks source link

Implemented events for when cache item is Added, Removed & Retrieved. #7

Closed pm7y closed 7 years ago

pm7y commented 8 years ago
alastairtree commented 8 years ago

Hi. Thanks for contributing! Just trying to understand it - could you give me an idea of why you might want this feature/a sample use case? Is it not something that could already be achieved using the callbacks on the CacheItemPolicy class such as UpdateCallback and RemovedCallback?

Because of the ignored test/issue with update events it feels a little bit half baked, could it be completed using UpdateCallback on the policy? Also the other angle to explore is the change monitor on the ObjectCache although that is more for per-key monitoring rather than general notification it seems.

abatishchev commented 8 years ago

Do such events add cost to the operations? I'm asking because believe that 98℅ consumers won't use them. Thus would suggest do not bake them in, instead have some sort of decorator so consider would explxiitlty opt-in to the version having event as such.

alastairtree commented 7 years ago

I believe this is a niche feature that is something that could be achieved already using the callbacks on the CacheItemPolicy class such as UpdateCallback and RemovedCallback and an easy wrapper class around the cache service without modification of the core code. As such I have decided to leave this as a fork and not merge it in. I have however updated the docs on using callbacks on cache policies, see https://github.com/alastairtree/LazyCache/wiki/1.0-LazyCache-API-documentation#custom-cache-policies

Still want to say thank you for your contribution and hope leaving it here may help others.