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

Running the "Add" operation in a background process to for performance reasons #220

Closed aramkoukia closed 6 years ago

aramkoukia commented 6 years ago

Hi, In case where our configuration is a "memory cache" backed by "redis", seems like "Add" always adds the object to Redis first, hence it needs to serialize the object first and I guess it is causing performance issues for us. Does it make sense to run "Add" operations as a "background process" or a "fire and forget" call so the client is not waiting for the "Add" operation to complete?

MichaCo commented 6 years ago

Yes, Add has to add the item to the bottom most layer first, because only that layer knows if the item already exists and Add cares about that part..

Not sure if async processing would help as it doesn't resolve the actual (perf) problem. Maybe the current operation will be faster, but if more and more tasks are running, the performance will just get worse over time?

In the end, it depends on what your case is. How many operations there are and if you have to rely on the Add operation to return (to know if the item was added or not and for other consumers...)

But, most importantly, why is your serialization causing performance issues? Maybe you can optimize that by not caching/serializing too complex structures or by using a more efficient serializer?