diff --git a/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/DefaultMappingConfigProvider.cs b/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/DefaultMappingConfigProvider.cs index 2bc9e9e48..bf1136d5f 100644 --- a/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/DefaultMappingConfigProvider.cs +++ b/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/DefaultMappingConfigProvider.cs @@ -5,7 +5,7 @@ namespace Masa.Contrib.Data.Mapping.Mapster; public class DefaultMappingConfigProvider : IMappingConfigProvider { - private readonly ConcurrentDictionary<(Type SourceType, Type DestinationType, MapOptions? MapOptions), TypeAdapterConfig?> _store = new(); + private readonly MemoryCache<(Type SourceType, Type DestinationType, MapOptions? MapOptions), TypeAdapterConfig?> _cache = new(); private readonly MapOptions _options; @@ -16,7 +16,7 @@ public TypeAdapterConfig GetConfig(Type sourceType, Type destinationType, MapOpt protected virtual TypeAdapterConfig GetConfigByCache(Type sourceType, Type destinationType, MapOptions? options) { - TypeAdapterConfig? config = _store.GetOrAdd( + TypeAdapterConfig? config = _cache.GetOrAdd( (sourceType, destinationType, options), type => GetAdapterConfig(type.SourceType, type.DestinationType, options)); diff --git a/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/Masa.Contrib.Data.Mapping.Mapster.csproj b/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/Masa.Contrib.Data.Mapping.Mapster.csproj index 5fe32eab6..5a2b95d1a 100644 --- a/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/Masa.Contrib.Data.Mapping.Mapster.csproj +++ b/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/Masa.Contrib.Data.Mapping.Mapster.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/_Imports.cs b/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/_Imports.cs index b9b142b57..59a7f980d 100644 --- a/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/_Imports.cs +++ b/src/Data/Mapping/Masa.Contrib.Data.Mapping.Mapster/_Imports.cs @@ -8,8 +8,8 @@ global using Masa.BuildingBlocks.Data.Mapping.Options.Enum; global using Masa.Contrib.Data.Mapping.Mapster.Internal; global using Masa.Contrib.Data.Mapping.Mapster.Internal.Options; +global using Masa.Utils.Caching.Memory; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.DependencyInjection.Extensions; -global using System.Collections.Concurrent; global using System.Linq.Expressions; global using System.Reflection;