abp icon indicating copy to clipboard operation
abp copied to clipboard

Distributed Cache Improvements

Open hikalkan opened this issue 2 years ago • 5 comments

  • [ ] Use distributed locking for GetOrAdd... methods. Currently, we are using in-process locking, which is fine, but doesn't prevent multiple write operations. That means if the data is read from database, multiple processes unnecessarily read it multiple times. This can be a good optimization. This should be optional and per cache, because it has a cost. We can add an attribute to cacheitem class, like [UseDistributedLock] to indicate it.
  • [ ] Implement in-memory cache layer. This would be good for rarely changing big data. I've implemented a similar thing manually for dynamic permissions (DynamicPermissionDefinitionStore and DynamicPermissionDefinitionStoreInMemoryCache classes can be checked). This covers https://github.com/abpframework/abp/issues/3854 too. Note that we should enable this only for real distributed caches, not for the default memory cache - it is already in-memory. This should be optional and per cache, because it has a cost and not necessary for all objects. We can add an attribute to cacheitem class, like [UseInMemoryCacheLayer] to indicate it. We can also benefit from cache server's (e.g. Redis) events to get notified when the cached item has changed (updated/deleted) if the server supports.

hikalkan avatar Sep 07 '22 08:09 hikalkan

https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-preview-6/ .NET 7 has new caching option - Output caching. Is this maybe somehow applicable for caching system described here?

leonkosak avatar Sep 08 '22 06:09 leonkosak

@leonkosak it is something different. It caches the whole HTTP response. We want to improve distributed cache in this issue.

hikalkan avatar Sep 11 '22 10:09 hikalkan

@hikalkan, thanks. Is Output Cache relevant for abp? As I can see, Output cache is also possible solution for multi-instance environments (kubernetes): https://www.youtube.com/watch?v=WeHZ_NMC-Jo

leonkosak avatar Sep 14 '22 19:09 leonkosak

Output cache can be used in every .NET project, including ABP-based ones. I suppose no specific point related to ABP here.

hikalkan avatar Sep 18 '22 16:09 hikalkan

Consider using https://github.com/ZiggyCreatures/FusionCache that is implemented on top of memory and distributed cache with functionality you are thinking to implement: https://github.com/ZiggyCreatures/FusionCache/blob/main/docs/Comparison.md

payoff avatar May 25 '23 13:05 payoff