|
@@ -14,13 +14,12 @@ type cache struct {
|
|
|
}
|
|
|
|
|
|
type CacheBlocks struct {
|
|
|
- mutex *sync.Mutex
|
|
|
+ sync.RWMutex
|
|
|
cacheBlocks map[string]cache
|
|
|
}
|
|
|
|
|
|
func New() *CacheBlocks {
|
|
|
return &CacheBlocks{
|
|
|
- mutex: &sync.Mutex{},
|
|
|
cacheBlocks: map[string]cache{},
|
|
|
}
|
|
|
}
|
|
@@ -38,9 +37,9 @@ func (this *CacheBlocks) prepare(host string) {
|
|
|
}
|
|
|
|
|
|
func (this *CacheBlocks) Reset(host string) {
|
|
|
- this.mutex.Lock()
|
|
|
+ this.Lock()
|
|
|
+ defer this.Unlock()
|
|
|
if _, ok := this.cacheBlocks[host]; ok {
|
|
|
delete(this.cacheBlocks, host)
|
|
|
}
|
|
|
- this.mutex.Unlock()
|
|
|
}
|