fix: 缓存未失效

This commit is contained in:
骑着蜗牛追导弹 2024-11-09 16:08:16 +08:00
parent b721357f2e
commit 36da229a19
3 changed files with 42 additions and 9 deletions

View File

@ -40,6 +40,7 @@ more than 7 hours
- 支持A、AAAA、MX、TXT、CNAME记录解析 - 支持A、AAAA、MX、TXT、CNAME记录解析
## 待办清单 ## 待办清单
- 支持回滚 2024-11-08 [ok] - 支持回滚 2024-11-08 [ok]
- 添加缓存 2024-11-09 [ok] - 添加缓存 2024-11-09 [ok]
@ -62,8 +63,14 @@ gcc -v
``` ```
#### 编译 #### 编译
- GOOS代表程序构建环境的目标操作系统其值可以是liunxwindowsfreebsddarwin - GOOS代表程序构建环境的目标操作系统其值可以是liunxwindowsfreebsddarwin
- GORACH代表程序构建环境的目标计算架构其值可以是386amd64或arm - GORACH代表程序构建环境的目标计算架构其值可以是386amd64或arm
```text
首先,配置代理,并在项目根目录执行 go mod tidy 安装依赖
```
```shell ```shell
# Windows # Windows
set GOOS=windows set GOOS=windows
@ -71,6 +78,7 @@ set GOARCH=amd64
set CGO_ENABLED=0 set CGO_ENABLED=0
go build -o ./bin/kenaito-dns_windows_amd64 main.go go build -o ./bin/kenaito-dns_windows_amd64 main.go
``` ```
```shell ```shell
# Linux # Linux
set GOOS=linux set GOOS=linux
@ -78,6 +86,7 @@ set GOARCH=amd64
set CGO_ENABLED=0 set CGO_ENABLED=0
go build -o ./bin/kenaito-dns_linux_amd64 main.go go build -o ./bin/kenaito-dns_linux_amd64 main.go
``` ```
```shell ```shell
# Mac # Mac
set GOOS=darwin set GOOS=darwin
@ -87,15 +96,27 @@ go build -o ./bin/kenaito-dns_darwin_amd64 main.go
``` ```
#### 运行 #### 运行
```shell
# 例子在Windows平台上
# 将编译产出的 kenaito-dns_windows_amd64 与 dns.sqlite3 文件放在同一目录下, 执行以下命令运行即可
./kenaito-dns_windows_amd64
```
![jietu1](https://oss.odboy.cn/blog/files/onlinedoc/kenaito-dns/P20241109140144.png)
#### 解析测试 ```shell
- 新增解析对比操作 # 例子:在 Mac 平台上
# 将编译产出的 kenaito-dns_darwin_amd64 与 dns.sqlite3 文件放在同一目录下, 执行以下命令运行即可
./kenaito-dns_darwin_amd64
```
![jietu1](https://oss.odboy.cn/blog/files/onlinedoc/kenaito-dns/jietu1.png)
#### 测试
```text
服务所在的ip地址为 192.168.43.130
所需工具brew install watch
测试命令watch -n 2 nslookup demo2024.odboy.cn 192.168.43.130
```
- 新增A解析记录
- 删除A解析记录
- 修改A解析记录
- 回滚解析记录
## 常见问题 ## 常见问题

View File

@ -13,6 +13,8 @@ var IdResolveRecordMap sync.Map
func ReloadCache() { func ReloadCache() {
fmt.Println("[app] [info] " + time.Now().Format(config.AppTimeFormat) + " [Cache] Reload cache start") fmt.Println("[app] [info] " + time.Now().Format(config.AppTimeFormat) + " [Cache] Reload cache start")
KeyResolveRecordMap.Range(cleanKeyCache)
IdResolveRecordMap.Range(cleanIdCache)
resolveRecords := dao.FindResolveRecordByVersion(dao.GetResolveVersion()) resolveRecords := dao.FindResolveRecordByVersion(dao.GetResolveVersion())
for _, record := range resolveRecords { for _, record := range resolveRecords {
// id -> resolveRecord // id -> resolveRecord
@ -32,3 +34,13 @@ func ReloadCache() {
} }
fmt.Println("[app] [info] " + time.Now().Format(config.AppTimeFormat) + " [Cache] Reload cache end") fmt.Println("[app] [info] " + time.Now().Format(config.AppTimeFormat) + " [Cache] Reload cache end")
} }
func cleanKeyCache(key any, value any) bool {
KeyResolveRecordMap.Delete(key)
return true
}
func cleanIdCache(key any, value any) bool {
IdResolveRecordMap.Delete(key)
return true
}

2
go.mod
View File

@ -7,6 +7,7 @@ require (
github.com/go-xorm/xorm v0.7.9 github.com/go-xorm/xorm v0.7.9
github.com/mattn/go-sqlite3 v1.14.24 github.com/mattn/go-sqlite3 v1.14.24
github.com/miekg/dns v1.1.62 github.com/miekg/dns v1.1.62
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb
) )
require ( require (
@ -43,5 +44,4 @@ require (
google.golang.org/protobuf v1.34.1 // indirect google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect
) )