| 123 | } |
| 124 | |
| 125 | func (this *OpenFileCache) Close(filename string) { |
| 126 | filename = filepath.Clean(filename) |
| 127 | |
| 128 | this.locker.Lock() |
| 129 | |
| 130 | pool, ok := this.poolMap[filename] |
| 131 | if ok { |
| 132 | // 设置关闭状态 |
| 133 | pool.SetClosing() |
| 134 | |
| 135 | delete(this.poolMap, filename) |
| 136 | this.poolList.Remove(pool.linkItem) |
| 137 | _ = this.watcher.Remove(filename) |
| 138 | this.count -= pool.Len() |
| 139 | this.usedSize -= pool.usedSize |
| 140 | } |
| 141 | |
| 142 | this.locker.Unlock() |
| 143 | |
| 144 | // 在locker之外,提升性能 |
| 145 | if ok { |
| 146 | pool.Close() |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | func (this *OpenFileCache) CloseAll() { |
| 151 | this.locker.Lock() |