dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.64k stars 123 forks source link

ConcurrentCache is obsolete #251

Closed adambajguz closed 1 month ago

adambajguz commented 1 month ago

Hi, the ConcurrentCache is currently marked as obsolete as RandomAccessCache was created. However, the ConcurrentCache has one big adventage - all methods ale synchornous which is very useful for e.g. value objects caching.

Do you plan to add a LRU synchronous cache or remove the obsolete attribute?

sakno commented 1 month ago

all methods ale synchronous which is very useful for e.g. value objects caching.

True. But first you need to initialize the object. Typically, it is serialized in some form on the disk or database. Deserialization is asynchronous process. Could you explain how the object is creating when it needs to be added to the cache?

Do you plan to add a LRU synchronous cache

LRU cannot be implemented in a lock-free manner. This is the main disadvantage in contrast to SIEVE algorithm implemented by RandomAccessCache. ConcurrentCache use locks even for read-only operations. However, it tries to load-balance the queue drain between the threads.

Probably, the best approach is to offer synchronous cache based on SIEVE (which requires some effort).

sakno commented 1 month ago

I have good news. In the new release of DotNext.Threading I've added support for synchronous lock acquisition to async-friendly synchronization primitives such as AsyncExclusiveLock. This fact unlocks the possibility to add synchronous methods to RandomAccessCache. This is done as well.

adambajguz commented 1 month ago

Wow, thanks!