evcc-io/tariff/proxy_cache.go
Michael Geers a8c16f2853
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled
Add dedicated db cache table (#22650)
2025-08-02 10:04:17 +02:00

30 lines
605 B
Go

package tariff
import (
"crypto/sha256"
"fmt"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/server/db/cache"
)
type cached struct {
Type api.TariffType `json:"type"`
Rates api.Rates `json:"rates"`
}
func cacheKey(typ string, other map[string]any) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s-%v", typ, other))))
}
func cachePut(key string, typ api.TariffType, rates api.Rates) error {
return cache.Put(key, &cached{
Type: typ,
Rates: rates,
})
}
func cacheGet(key string) (*cached, error) {
var res cached
return &res, cache.Get(key, &res)
}