Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(Caching): Delete the overloaded part to optimize the user experience #315

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static IServiceCollection AddOidcCache(this IServiceCollection services,
services.AddMultilevelCache(
Constants.DEFAULT_CLIENT_NAME,
distributedCacheOptions => distributedCacheOptions.UseStackExchangeRedisCache(options),
null,
multilevelCacheOptions =>
{
multilevelCacheOptions.SubscribeKeyType = SubscribeKeyType.SpecificPrefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,10 @@ public void TestMultilevelCache()
distributedCacheOptions => distributedCacheOptions.UseStackExchangeRedisCache(_ =>
{
}),
new MultilevelCacheOptions()
multilevelCacheOptions =>
{
SubscribeKeyPrefix = "masa",
SubscribeKeyType = SubscribeKeyType.ValueTypeFullNameAndKey
multilevelCacheOptions.SubscribeKeyPrefix = "masa";
multilevelCacheOptions.SubscribeKeyType = SubscribeKeyType.ValueTypeFullNameAndKey;
});
var serviceProvider = services.BuildServiceProvider();
var multilevelCacheClient = serviceProvider.GetRequiredService<IMultilevelCacheClient>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ public void TestFormatCacheKeyByTypeNameAlias()
var services = new ServiceCollection();
services.AddMultilevelCache(distributedCacheOptions =>
distributedCacheOptions.UseStackExchangeRedisCache(RedisConfigurationOptions),
typeAliasOptions =>
multilevelCacheOptions =>
{
typeAliasOptions.GetAllTypeAliasFunc = () => new Dictionary<string, string>()
multilevelCacheOptions.GlobalCacheOptions = new CacheOptions()
{
{ "String", "s" }
CacheKeyType = CacheKeyType.TypeAlias
};
},
multilevelCacheOptions =>
typeAliasOptions =>
{
multilevelCacheOptions.GlobalCacheOptions = new CacheOptions()
typeAliasOptions.GetAllTypeAliasFunc = () => new Dictionary<string, string>()
{
CacheKeyType = CacheKeyType.TypeAlias
{ "String", "s" }
};
}
);
Expand All @@ -251,6 +251,7 @@ public void TestFormatCacheKeyByTypeNameAlias2()
var builder = WebApplication.CreateBuilder();
builder.Services.AddMultilevelCache(distributedCacheOptions =>
distributedCacheOptions.UseStackExchangeRedisCache(RedisConfigurationOptions),
"MultilevelCache",
typeAliasOptions =>
{
typeAliasOptions.GetAllTypeAliasFunc = () => new Dictionary<string, string>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public static class ServiceCollectionExtensions
public static IServiceCollection AddMultilevelCache(
this IServiceCollection services,
Action<DistributedCacheOptions> distributedCacheAction,
Action<TypeAliasOptions>? typeAliasOptionsAction = null,
Action<MultilevelCacheOptions>? multilevelCacheOptionsAction = null)
Action<MultilevelCacheOptions>? multilevelCacheOptionsAction = null,
Action<TypeAliasOptions>? typeAliasOptionsAction = null)
{
if (multilevelCacheOptionsAction == null)
{
Expand All @@ -23,14 +23,14 @@ public static IServiceCollection AddMultilevelCache(
return services.AddMultilevelCache(
Microsoft.Extensions.Options.Options.DefaultName,
distributedCacheAction,
typeAliasOptionsAction,
multilevelCacheOptionsAction);
multilevelCacheOptionsAction,
typeAliasOptionsAction);
}

public static IServiceCollection AddMultilevelCache(
this IServiceCollection services,
Action<DistributedCacheOptions> distributedCacheAction,
string sectionName,
string sectionName = Const.DEFAULT_SECTION_NAME,
Action<TypeAliasOptions>? typeAliasOptionsAction = null)
=> services.AddMultilevelCache(
distributedCacheAction,
Expand All @@ -41,7 +41,7 @@ public static IServiceCollection AddMultilevelCache(
public static IServiceCollection AddMultilevelCache(
this IServiceCollection services,
Action<DistributedCacheOptions> distributedCacheAction,
string sectionName,
string sectionName = Const.DEFAULT_SECTION_NAME,
bool isReset = false,
Action<TypeAliasOptions>? typeAliasOptionsAction = null)
=> services.AddMultilevelCache(
Expand Down Expand Up @@ -79,36 +79,12 @@ public static IServiceCollection AddMultilevelCache(
return services;
}

public static IServiceCollection AddMultilevelCache(
this IServiceCollection services,
Action<DistributedCacheOptions> distributedCacheAction,
MultilevelCacheOptions multilevelCacheOptions,
Action<TypeAliasOptions>? typeAliasOptionsAction = null)
=> services.AddMultilevelCache(
Microsoft.Extensions.Options.Options.DefaultName,
distributedCacheAction,
multilevelCacheOptions,
typeAliasOptionsAction);

public static IServiceCollection AddMultilevelCache(
this IServiceCollection services,
string name,
Action<DistributedCacheOptions> distributedCacheAction,
MultilevelCacheOptions multilevelCacheOptions,
Action<MultilevelCacheOptions>? multilevelCacheOptionsAction = null,
Action<TypeAliasOptions>? typeAliasOptionsAction = null)
{
services.AddMultilevelCache(name, multilevelCacheOptions, typeAliasOptionsAction);
var distributedCacheOptions = new DistributedCacheOptions(services, name);
distributedCacheAction.Invoke(distributedCacheOptions);
return services;
}

public static IServiceCollection AddMultilevelCache(
this IServiceCollection services,
string name,
Action<DistributedCacheOptions> distributedCacheAction,
Action<TypeAliasOptions>? typeAliasOptionsAction,
Action<MultilevelCacheOptions>? multilevelCacheOptionsAction = null)
{
MultilevelCacheOptions multilevelCacheOptions = new();
multilevelCacheOptionsAction?.Invoke(multilevelCacheOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ var redisConfigurationOptions = new RedisConfigurationOptions()
builder.Services
.AddMultilevelCache(
distributedCacheOptions => distributedCacheOptions.UseStackExchangeRedisCache(redisConfigurationOptions),
new MultilevelCacheOptions()
multilevelCacheOptions =>
{
SubscribeKeyPrefix = "masa",
SubscribeKeyType = SubscribeKeyType.ValueTypeFullNameAndKey
multilevelCacheOptions.SubscribeKeyPrefix = "masa";
multilevelCacheOptions.SubscribeKeyType = SubscribeKeyType.ValueTypeFullNameAndKey;
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ var redisConfigurationOptions = new RedisConfigurationOptions()
builder.Services
.AddMultilevelCache(
distributedCacheOptions => distributedCacheOptions.UseStackExchangeRedisCache(redisConfigurationOptions),
new MultilevelCacheOptions()
multilevelCacheOptions =>
{
SubscribeKeyPrefix = "masa",
SubscribeKeyType = SubscribeKeyType.ValueTypeFullNameAndKey
multilevelCacheOptions.SubscribeKeyPrefix = "masa";
multilevelCacheOptions.SubscribeKeyType = SubscribeKeyType.ValueTypeFullNameAndKey;
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static IMasaConfigurationBuilder UseDcc(
services.AddMultilevelCache(
DEFAULT_CLIENT_NAME,
distributedCacheOptions => distributedCacheOptions.UseStackExchangeRedisCache(dccOptions.RedisOptions),
null,
multilevelCacheOptions =>
{
multilevelCacheOptions.GlobalCacheOptions = new CacheOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ public void TestGetSecretRenturnSecretEqualSecret()
new("localhost", 6379)
}
}),
new MultilevelCacheOptions()
multilevelCacheOptions =>
{
GlobalCacheOptions = new CacheOptions()
multilevelCacheOptions.GlobalCacheOptions = new CacheOptions()
{
CacheKeyType = CacheKeyType.None
}
};
}
);
var serviceProvider = builder.Services.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static IServiceCollection AddAuthClient(this IServiceCollection services,
services.AddMultilevelCache(
DEFAULT_CLIENT_NAME,
distributedCacheOptions => distributedCacheOptions.UseStackExchangeRedisCache(redisOptions),
null,
multilevelCacheOptions =>
{
multilevelCacheOptions.SubscribeKeyType = SubscribeKeyType.SpecificPrefix;
Expand Down