sftpgo/webdavd/mimecache.go
Nicola Murino 0a14297b48
webdav: performance improvements and bug fixes
we need my custom golang/x/net/webdav fork for now

https://github.com/drakkan/net/tree/sftpgo
2020-11-04 19:11:40 +01:00

35 lines
506 B
Go

package webdavd
import "sync"
type mimeCache struct {
maxSize int
sync.RWMutex
mimeTypes map[string]string
}
var mimeTypeCache mimeCache
func (c *mimeCache) addMimeToCache(key, value string) {
c.Lock()
defer c.Unlock()
if key == "" || value == "" {
return
}
if len(c.mimeTypes) >= c.maxSize {
return
}
c.mimeTypes[key] = value
}
func (c *mimeCache) getMimeFromCache(key string) string {
c.RLock()
defer c.RUnlock()
if val, ok := c.mimeTypes[key]; ok {
return val
}
return ""
}