From e01f056338b9d5c52c2717b256ccd23d9aa81b65 Mon Sep 17 00:00:00 2001 From: feijie Date: Tue, 10 Dec 2024 20:54:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(docs):=20=E6=B7=BB=E5=8A=A0IP2Region?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/LINGYUN.Abp.IP2Region/README.EN.md | 106 ++++++++++++++++++ .../common/LINGYUN.Abp.IP2Region/README.md | 65 +++++++++-- 2 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.EN.md diff --git a/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.EN.md b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.EN.md new file mode 100644 index 000000000..ad65a6fc7 --- /dev/null +++ b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.EN.md @@ -0,0 +1,106 @@ +# LINGYUN.Abp.IP2Region + +## Introduction + +`LINGYUN.Abp.IP2Region` is an ABP framework module based on IP2Region, providing IP address query functionality. This module integrates the IP2Region.Net library and provides convenient IP address query services. + +## Features + +* Provides IP address query service +* Supports multiple caching strategies +* Built-in IP database file +* Supports ABP virtual file system + +## Installation + +```bash +dotnet add package LINGYUN.Abp.IP2Region +``` + +## Usage + +1. Add `[DependsOn(typeof(AbpIP2RegionModule))]` to your module class. + +```csharp +[DependsOn(typeof(AbpIP2RegionModule))] +public class YourModule : AbpModule +{ + // ... +} +``` + +2. Inject and use the IP query service: + +```csharp +public class YourService +{ + private readonly ISearcher _searcher; + + public YourService(ISearcher searcher) + { + _searcher = searcher; + } + + public async Task SearchIpInfo(string ip) + { + return await _searcher.SearchAsync(ip); + } +} +``` + +## IP2Region.Net Library Description + +### Installation + +Install the package with [NuGet](https://www.nuget.org/packages/IP2Region.Net) + +```bash +Install-Package IP2Region.Net +``` + +### Usage + +```csharp +using IP2Region.Net.Abstractions; +using IP2Region.Net.XDB; + +ISearcher searcher = new Searcher(CachePolicy , "your xdb file path"); +``` + +### Cache Policy Description +| Cache Policy | Description | Thread Safe | +|-------------------------|------------------------------------------------------------------------------------------------------------|-------------| +| CachePolicy.Content | Cache the entire `xdb` data. | Yes | +| CachePolicy.VectorIndex | Cache `vecotorIndex` to speed up queries and reduce system io pressure by reducing one fixed IO operation. | Yes | +| CachePolicy.File | Completely file-based queries | Yes | + +### XDB File Description +Generate using [maker](https://github.com/lionsoul2014/ip2region/tree/master/maker/csharp), or [download](https://github.com/lionsoul2014/ip2region/blob/master/data/ip2region.xdb) pre-generated xdb files + +## Performance + +``` ini +BenchmarkDotNet=v0.13.2, OS=macOS 13.4.1 (c) (22F770820d) [Darwin 22.5.0] +Apple M1, 1 CPU, 8 logical and 8 physical cores +.NET SDK=7.0.306 + [Host] : .NET 6.0.20 (6.0.2023.32017), Arm64 RyuJIT AdvSIMD + DefaultJob : .NET 6.0.20 (6.0.2023.32017), Arm64 RyuJIT AdvSIMD +``` + +| Method | Mean | Error | StdDev | +|-------------------------|-----------:|---------:|---------:| +| CachePolicy_Content | 155.7 ns | 0.46 ns | 0.39 ns | +| CachePolicy_File | 2,186.8 ns | 34.27 ns | 32.06 ns | +| CachePolicy_VectorIndex | 1,570.3 ns | 27.53 ns | 22.99 ns | + +## Contributing +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. + +Please make sure to update tests as appropriate. + +## License +[Apache License 2.0](https://github.com/lionsoul2014/ip2region/blob/master/LICENSE.md) + +## Links + +* [中文文档](./README.md) diff --git a/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.md b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.md index 8f8c78c98..da3373d90 100644 --- a/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.md +++ b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/README.md @@ -1,8 +1,56 @@ -# IP2Region.Net +# LINGYUN.Abp.IP2Region -.NET client library for IP2Region +## 介绍 -## Installation +`LINGYUN.Abp.IP2Region` 是一个基于IP2Region的ABP框架模块,提供IP地址查询功能。本模块集成了IP2Region.Net库,提供了便捷的IP地址查询服务。 + +## 功能 + +* 提供IP地址查询服务 +* 支持多种缓存策略 +* 内置IP数据库文件 +* 支持ABP虚拟文件系统 + +## 安装 + +```bash +dotnet add package LINGYUN.Abp.IP2Region +``` + +## 使用 + +1. 添加 `[DependsOn(typeof(AbpIP2RegionModule))]` 到你的模块类上。 + +```csharp +[DependsOn(typeof(AbpIP2RegionModule))] +public class YourModule : AbpModule +{ + // ... +} +``` + +2. 注入并使用IP查询服务: + +```csharp +public class YourService +{ + private readonly ISearcher _searcher; + + public YourService(ISearcher searcher) + { + _searcher = searcher; + } + + public async Task SearchIpInfo(string ip) + { + return await _searcher.SearchAsync(ip); + } +} +``` + +## IP2Region.Net 库说明 + +### Installation Install the package with [NuGet](https://www.nuget.org/packages/IP2Region.Net) @@ -10,7 +58,7 @@ Install the package with [NuGet](https://www.nuget.org/packages/IP2Region.Net) Install-Package IP2Region.Net ``` -## Usage +### Usage ```csharp using IP2Region.Net.Abstractions; @@ -18,6 +66,7 @@ using IP2Region.Net.XDB; ISearcher searcher = new Searcher(CachePolicy , "your xdb file path"); ``` + ### Cache Policy Description | Cache Policy | Description | Thread Safe | |-------------------------|------------------------------------------------------------------------------------------------------------|-------------| @@ -51,12 +100,14 @@ Apple M1, 1 CPU, 8 logical and 8 physical cores | CachePolicy_File | 2,186.8 ns | 34.27 ns | 32.06 ns | | CachePolicy_VectorIndex | 1,570.3 ns | 27.53 ns | 22.99 ns | - - ## Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate. ## License -[Apache License 2.0](https://github.com/lionsoul2014/ip2region/blob/master/LICENSE.md) \ No newline at end of file +[Apache License 2.0](https://github.com/lionsoul2014/ip2region/blob/master/LICENSE.md) + +## 链接 + +* [English document](./README.EN.md) \ No newline at end of file