package grib

import (
	"sync"
	"time"
)

type vec [2]float64

type item struct {
	v   vec
	exp time.Time
}

type memCache struct {
	ttl time.Duration
	m   sync.Map
}

func (c *memCache) get(k uint64) (vec, bool) {
	if v, ok := c.m.Load(k); ok {
		it := v.(item)
		if time.Now().Before(it.exp) {
			return it.v, true
		}
		c.m.Delete(k)
	}
	return vec{}, false
}

func (c *memCache) set(k uint64, v vec) { c.m.Store(k, item{v, time.Now().Add(c.ttl)}) }
