Skip to content

Commit 7d76067

Browse files
committed
feat: 增加 CachePolicy 配置项
1 parent 3e63d81 commit 7d76067

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/components/BootstrapBlazor.IP2Region/Extensions/ServiceCollectionExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

@@ -15,14 +15,19 @@ public static class ServiceCollectionExtensions
1515
/// 添加 IP2RegionService 服务
1616
/// </summary>
1717
/// <param name="services"></param>
18-
public static IServiceCollection AddBootstrapBlazorIP2RegionService(this IServiceCollection services)
18+
/// <param name="configureOptions"></param>
19+
public static IServiceCollection AddBootstrapBlazorIP2RegionService(this IServiceCollection services, Action<IP2RegionOptions>? configureOptions = null)
1920
{
2021
services.AddSingleton<IIpLocatorProvider, IP2RegionService>();
2122
#if NET8_0_OR_GREATER
2223
services.AddKeyedSingleton<IIpLocatorProvider, IP2RegionService>("BootstrapBlazor.IP2Region");
2324
#endif
2425

2526
services.AddOptionsMonitor<IP2RegionOptions>();
27+
services.Configure<IP2RegionOptions>(options =>
28+
{
29+
configureOptions?.Invoke(options);
30+
});
2631
return services;
2732
}
2833
}

src/components/BootstrapBlazor.IP2Region/Options/IP2RegionOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5+
using IP2Region.Net.XDB;
6+
57
namespace BootstrapBlazor.Components;
68

79
/// <summary>
@@ -13,4 +15,9 @@ public class IP2RegionOptions
1315
/// 获取/设置 IP2Region 数据文件路径
1416
/// </summary>
1517
public string? XdbPath { get; set; }
18+
19+
/// <summary>
20+
/// 获得/设置 缓存策略 默认 <see cref="CachePolicy.Content"/>
21+
/// </summary>
22+
public CachePolicy CachePolicy { get; set; } = CachePolicy.Content;
1623
}

0 commit comments

Comments
 (0)