Skip to content

Commit 6b0097a

Browse files
committed
Compatible with the new version of HybridCache.
1 parent 9f89f16 commit 6b0097a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.4" />
8989
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
9090
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.4" />
91-
<PackageVersion Include="Microsoft.Extensions.Caching.Hybrid" Version="9.1.0-preview.1.25064.3" />
91+
<PackageVersion Include="Microsoft.Extensions.Caching.Hybrid" Version="9.4.0" />
9292
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.4" />
9393
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.4" />
9494
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.4" />

framework/src/Volo.Abp.Caching/Volo/Abp/Caching/AbpCachingModule.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using System;
3-
using Microsoft.Extensions.Caching.Hybrid;
4-
using Microsoft.Extensions.DependencyInjection.Extensions;
53
using Volo.Abp.Caching.Hybrid;
64
using Volo.Abp.Json;
75
using Volo.Abp.Modularity;
@@ -28,9 +26,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
2826
context.Services.AddSingleton(typeof(IDistributedCache<>), typeof(DistributedCache<>));
2927
context.Services.AddSingleton(typeof(IDistributedCache<,>), typeof(DistributedCache<,>));
3028

31-
#pragma warning disable EXTEXP0018
3229
context.Services.AddHybridCache().AddSerializerFactory<AbpHybridCacheJsonSerializerFactory>();
33-
#pragma warning restore EXTEXP0018
3430
context.Services.AddSingleton(typeof(IHybridCache<>), typeof(AbpHybridCache<>));
3531
context.Services.AddSingleton(typeof(IHybridCache<,>), typeof(AbpHybridCache<,>));
3632

framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Hybrid/AbpHybridCache.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class AbpHybridCache<TCacheItem, TCacheKey> : IHybridCache<TCacheItem, TC
7575

7676
protected HybridCache HybridCache { get; }
7777

78-
protected IDistributedCache DistributedCacheCache { get; }
78+
protected IDistributedCache DistributedCache { get; }
7979

8080
protected ICancellationTokenProvider CancellationTokenProvider { get; }
8181

@@ -105,7 +105,7 @@ public AbpHybridCache(
105105
ServiceProvider = serviceProvider;
106106
DistributedCacheOption = distributedCacheOption.Value;
107107
HybridCache = hybridCache;
108-
DistributedCacheCache = distributedCache;
108+
DistributedCache = distributedCache;
109109
CancellationTokenProvider = cancellationTokenProvider;
110110
Logger = NullLogger<AbpHybridCache<TCacheItem, TCacheKey>>.Instance;
111111
KeyNormalizer = keyNormalizer;
@@ -215,10 +215,15 @@ protected virtual void SetDefaultOptions()
215215
}
216216
}
217217

218-
var bytes = await DistributedCacheCache.GetAsync(NormalizeKey(key), token);
219-
if (bytes != null)
218+
if (await DistributedCache.GetAsync(NormalizeKey(key), token) != null)
220219
{
221-
return ResolveSerializer().Deserialize(new ReadOnlySequence<byte>(bytes, 0, bytes.Length));;
220+
// Because HybridCache wraps the cache in L2(distributed cache), we can’t unwrap it directly and can only retrieve the value through its API
221+
return await HybridCache.GetOrCreateAsync(
222+
key: NormalizeKey(key),
223+
factory: async cancel => await factory(),
224+
options: optionsFactory?.Invoke(),
225+
tags: null,
226+
cancellationToken: token);
222227
}
223228

224229
value = await factory();

0 commit comments

Comments
 (0)