CleanMatchKey 清理通配符匹配的缓存数据,类似于 https://*.example.com/hello
(key string)
| 124 | |
| 125 | // CleanMatchKey 清理通配符匹配的缓存数据,类似于 https://*.example.com/hello |
| 126 | func (this *MemoryList) CleanMatchKey(key string) error { |
| 127 | if strings.Contains(key, SuffixAll) { |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | u, err := url.Parse(key) |
| 132 | if err != nil { |
| 133 | return nil |
| 134 | } |
| 135 | |
| 136 | var host = u.Host |
| 137 | hostPart, _, err := net.SplitHostPort(host) |
| 138 | if err == nil && len(hostPart) > 0 { |
| 139 | host = hostPart |
| 140 | } |
| 141 | |
| 142 | if len(host) == 0 { |
| 143 | return nil |
| 144 | } |
| 145 | var requestURI = u.RequestURI() |
| 146 | |
| 147 | this.locker.RLock() |
| 148 | defer this.locker.RUnlock() |
| 149 | |
| 150 | // TODO 需要优化性能,支持千万级数据低于1s的处理速度 |
| 151 | for _, itemMap := range this.itemMaps { |
| 152 | for _, item := range itemMap { |
| 153 | if configutils.MatchDomain(host, item.Host) { |
| 154 | var itemRequestURI = item.RequestURI() |
| 155 | if itemRequestURI == requestURI || strings.HasPrefix(itemRequestURI, requestURI+SuffixAll) { |
| 156 | item.ExpiresAt = 0 |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return nil |
| 163 | } |
| 164 | |
| 165 | // CleanMatchPrefix 清理通配符匹配的缓存数据,类似于 https://*.example.com/prefix/ |
| 166 | func (this *MemoryList) CleanMatchPrefix(prefix string) error { |
nothing calls this directly
no test coverage detected