42 lines
594 B
Go
42 lines
594 B
Go
package exporter
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
type Cache[T any] struct {
|
|
data map[string]T
|
|
mutex sync.RWMutex
|
|
}
|
|
|
|
func NewCache[T any]() *Cache[T] {
|
|
return &Cache[T]{
|
|
data: make(map[string]T),
|
|
}
|
|
}
|
|
|
|
func (c *Cache[T]) Set(key string, value T) {
|
|
key = strings.ToLower(key)
|
|
c.mutex.Lock()
|
|
defer c.mutex.Unlock()
|
|
|
|
c.data[key] = value
|
|
}
|
|
|
|
func (c *Cache[T]) Get(key string) (T, bool) {
|
|
key = strings.ToLower(key)
|
|
c.mutex.RLock()
|
|
defer c.mutex.RUnlock()
|
|
|
|
value, ok := c.data[key]
|
|
return value, ok
|
|
}
|
|
|
|
type CacheItem struct {
|
|
Path string
|
|
Size int64
|
|
Bytes *bytes.Buffer
|
|
}
|