How to make AppCaches distributed?
# help-with-umbraco
g
We are using isolated [Application Cache](https://docs.umbraco.com/umbraco-cms/reference/cache/application-cache) for storing some data from an external API. We recently implemented distributed cache in SQL server.
Copy code
builder.Services.AddDistributedSqlServerCache(options =>
{
    options.TableName = nameof(CacheStore);
    options.ConnectionString = builder.Config.GetConnectionString("umbracoDbDSN");
});
How to make the application caches also shared between our kubernetes pods? Is this even intended to use or is Applicaiton Cache meant to be available only on one machine? Should we refactor the Cache implementation to use service
IDistributedCache
instead of
AppCaches
? Is there any example of that anywhere? Thank you
b
Why don't you use Redis for this?
g
Would it make any difference ? By the [docs](https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-8.0), you can use any of the distributed cahce provides, so I think SQL should work aswell.
k
Well, there's an Umbraco aspect to this, and an ASP.NET Core aspect, and a hosting/kubernetes aspect.
IDistributedCache
is an aspnetcore concept but Umbraco has a
DistributedCache
class with helper methods. The Umbraco docs are a bit vague but from the looks of it you should use Isolated Caches in Umbraco and use the
DistributedCache
helpers to manage the cache, so not use the aspnetcore cache stuff directly. For the shared-between-pods part it will simply depend on whether the pods use the same database. I agree that using Redis or SQL as the actual distributed cache provider makes no difference to Umbraco.
g
Looking at the
DistributedCache
implementation (
Umbraco.Cms.Core.Cache
) I can only see refresh methods there. I know those are used to refresh the Isolated cache on the different servers, but this seem to only be some kind of notifications implementation, so that each server knows that it should remove its own instance of the cache. Doesn't help me with the actual distributed cache.
b
another option we are currently moving to is FusionCache https://github.com/ZiggyCreatures/FusionCache/. It is primarily a memory cache, but you can add a distributed cache layer, and also a backplane layer to manage updates towards the different instances. (much better described here: https://github.com/ZiggyCreatures/FusionCache/blob/main/docs/StepByStep.md). Backplane seems to be Redis only as far as I could see, but the distributed cache part can be configured to be SQL. We have tried pure IDistributedCache (with Redis in our case), and it does work, but lacks some of the things (stampede protection for instance), that you can potentially create as a wrapper, but FusionCache seems to be a better alternative for our case at least (not a lot of cached data, and mostly not large data either, so having them in memory is okay for us... they are accessed a lot though). HybridCache looks much better in this regard, but that will come in .NET 9 only unfortunately.
42 Views