2024-07-19 10:21:26 +03:00

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
}