mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 19:30:36 -06:00
34 lines
733 B
Go
34 lines
733 B
Go
package dashboards
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
gocache "github.com/patrickmn/go-cache"
|
|
"time"
|
|
)
|
|
|
|
type dashboardCache struct {
|
|
internalCache *gocache.Cache
|
|
}
|
|
|
|
func NewDashboardCache() *dashboardCache {
|
|
return &dashboardCache{internalCache: gocache.New(5*time.Minute, 30*time.Minute)}
|
|
}
|
|
|
|
func (fr *dashboardCache) addDashboardCache(key string, json *dashboards.SaveDashboardDTO) {
|
|
fr.internalCache.Add(key, json, time.Minute*10)
|
|
}
|
|
|
|
func (fr *dashboardCache) getCache(key string) (*dashboards.SaveDashboardDTO, bool) {
|
|
obj, exist := fr.internalCache.Get(key)
|
|
if !exist {
|
|
return nil, exist
|
|
}
|
|
|
|
dash, ok := obj.(*dashboards.SaveDashboardDTO)
|
|
if !ok {
|
|
return nil, ok
|
|
}
|
|
|
|
return dash, ok
|
|
}
|