Files
heloha/internal/server/tilecache.go
2026-04-25 20:31:55 -05:00

35 lines
770 B
Go

package server
import "sync"
// TileCache is a thread-safe in-memory cache for rendered PNG tiles.
// Keys are "z/x/y". The entire cache is invalidated on each new radar scan.
type TileCache struct {
mu sync.RWMutex
tiles map[string][]byte
}
func NewTileCache() *TileCache {
return &TileCache{tiles: make(map[string][]byte)}
}
func (c *TileCache) Get(key string) ([]byte, bool) {
c.mu.RLock()
defer c.mu.RUnlock()
v, ok := c.tiles[key]
return v, ok
}
func (c *TileCache) Set(key string, data []byte) {
c.mu.Lock()
defer c.mu.Unlock()
c.tiles[key] = data
}
// Invalidate clears all cached tiles. Call this after each new radar product is loaded.
func (c *TileCache) Invalidate() {
c.mu.Lock()
defer c.mu.Unlock()
c.tiles = make(map[string][]byte)
}