| 178 | } |
| 179 | |
| 180 | func (this *OpenFileCache) consumeHead() { |
| 181 | var delta = 1 |
| 182 | |
| 183 | if this.count > 100 { |
| 184 | delta = 2 |
| 185 | } |
| 186 | |
| 187 | for i := 0; i < delta; i++ { |
| 188 | var head = this.poolList.Head() |
| 189 | if head == nil { |
| 190 | break |
| 191 | } |
| 192 | |
| 193 | var headPool = head.Value |
| 194 | headFile, consumed, consumedSize := headPool.Get() |
| 195 | if consumed { |
| 196 | this.count-- |
| 197 | this.usedSize -= consumedSize |
| 198 | |
| 199 | if headFile != nil { |
| 200 | _ = headFile.Close() |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | if headPool.Len() == 0 { |
| 205 | delete(this.poolMap, headPool.filename) |
| 206 | this.poolList.Remove(head) |
| 207 | _ = this.watcher.Remove(headPool.filename) |
| 208 | } |
| 209 | } |
| 210 | } |