package services

import (
	"sync"

	"github.com/fiskerinc/cloud-services/pkg/cache"
	"github.com/fiskerinc/cloud-services/pkg/utils/envtool"
)

var (
	MAX_ECU_KEY_CACHE int = envtool.GetEnvInt("MAX_ECU_KEY_CACHE", 10000)
	ring              cache.RingMapInterface
	onceECUCache      sync.Once
)

func GetCarEcuCache() cache.RingMapInterface {
	onceECUCache.Do(func() {
		if ring == nil {
			ring = cache.NewRingMap(MAX_ECU_KEY_CACHE)
		}
	})

	return ring
}

func SetCarEcuCache(value cache.RingMapInterface) {
	ring = value
}
