CleanMatchPrefix 清理通配符匹配的缓存数据,类似于 https://*.example.com/prefix/
(prefix string)
| 164 | |
| 165 | // CleanMatchPrefix 清理通配符匹配的缓存数据,类似于 https://*.example.com/prefix/ |
| 166 | func (this *MemoryList) CleanMatchPrefix(prefix string) error { |
| 167 | u, err := url.Parse(prefix) |
| 168 | if err != nil { |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | var host = u.Host |
| 173 | hostPart, _, err := net.SplitHostPort(host) |
| 174 | if err == nil && len(hostPart) > 0 { |
| 175 | host = hostPart |
| 176 | } |
| 177 | if len(host) == 0 { |
| 178 | return nil |
| 179 | } |
| 180 | var requestURI = u.RequestURI() |
| 181 | var isRootPath = requestURI == "/" |
| 182 | |
| 183 | this.locker.RLock() |
| 184 | defer this.locker.RUnlock() |
| 185 | |
| 186 | // TODO 需要优化性能,支持千万级数据低于1s的处理速度 |
| 187 | for _, itemMap := range this.itemMaps { |
| 188 | for _, item := range itemMap { |
| 189 | if configutils.MatchDomain(host, item.Host) { |
| 190 | var itemRequestURI = item.RequestURI() |
| 191 | if isRootPath || strings.HasPrefix(itemRequestURI, requestURI) { |
| 192 | item.ExpiresAt = 0 |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return nil |
| 199 | } |
| 200 | |
| 201 | func (this *MemoryList) Remove(hash string) error { |
| 202 | this.locker.Lock() |
nothing calls this directly
no test coverage detected