From fb2e7fda12afa4685de2c43f634fd8a4f1312400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 19 Dec 2024 13:23:28 +0300 Subject: [PATCH] Update when-to-use-a-distributed-cache-server.md --- .../when-to-use-a-distributed-cache-server.md | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/en/kb/when-to-use-a-distributed-cache-server.md b/docs/en/kb/when-to-use-a-distributed-cache-server.md index 9ad97a4f2a..68bf5189e8 100644 --- a/docs/en/kb/when-to-use-a-distributed-cache-server.md +++ b/docs/en/kb/when-to-use-a-distributed-cache-server.md @@ -1,8 +1,39 @@ # Why to Use a Distributed Cache Server -TODO +ABP provides a [distributed cache service](../framework/fundamentals/caching.md) that is based on [ASP.NET Core's distributed cache](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed). +## Understanding the Default Cache Service +**Default implementation of the cache service works in-memory**. Memory cache is only useful if you are building a monolith application and you run a single instance of your application. For other cases, **you should use a real distributed cache server**. -See the [Redis Cache](./redis-cache.md) document if you need to use Redis as the distributed cache server. See [ASP.NET Core's documentation](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed) to see how to switch to another cache provider. +Here, a few example cases where you should use a distributed cache server: +* You have a **monolith application**, but you run **multiple instances** of that application concurrently, for example, in a [clustered environment](../deployment/clustered-environment.md) +* You build a **microservice** or any kind of **distributed** system +* You have web **multiple applications** in your solution and they should share the same cache + +The problem is obvious: If each application instance uses its internal in-memory cache, and if two or more applications cache the same data, it is probable that they will cache different copies of the data. In that case, there is no way to **invalidate/refresh** that data in every application's memory when the data changes. + +## What is a Distributed Cache Server + +A **distributed cache server** (e.g. [Redis](../framework/fundamentals/redis-cache.md)) stores cache objects in a separate server application and allows multiple applications/processes share the same cache objects. In that way; + +* All applications/services and all their instances use the same cache store and share the same cached objects. Once an application instance refreshes a cached object, all others use the new object. +* Even if your applications stop and restart, the cached objects are not lost, since they are managed by a separate cache server. + +## How to Use a Distributed Cache Server + +ABP [solution templates](../solution-templates/index.md) come with Redis configured when it is certainly necessary. For example; + +* The [microservice startup template](../solution-templates/microservice/index.md) always comes with [Redis configured](../solution-templates/microservice/distributed-cache.md) and also included as a docker container. + +* The application startup template comes with Redis configured when you select multiple applications, tiered architecture, etc. + +In other cases, to keep the dependencies minimal, they come with the default (in-memory) cache configuration. In that case, you should manually switch to a distributed cache provider for your application. + +See the *[Redis Cache](../framework/fundamentals/redis-cache.md)* document if you need to use Redis as the distributed cache server. See [ASP.NET Core's documentation](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed) to see how to switch to another cache provider. + +## See Also + +* [ABP Distributed Cache](../framework/fundamentals/caching.md) +* [ASP.NET Core Distributed Cache](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed)