phase 0-2 complete
This commit is contained in:
34
internal/server/tilecache.go
Normal file
34
internal/server/tilecache.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user