package metacache

import (
	"time"

	"gitlink.org.cn/cloudream/jcs-pub/client/internal/db"
)

type MetaCache interface {
	ClearOutdated()
}

type MetaCacheHost struct {
	db     *db.DB
	caches []MetaCache
}

func NewHost(db *db.DB) *MetaCacheHost {
	return &MetaCacheHost{
		db: db,
	}
}

func (m *MetaCacheHost) Serve() {
	ticker := time.NewTicker(time.Minute)
	for {
		select {
		case <-ticker.C:
			for _, cache := range m.caches {
				cache.ClearOutdated()
			}
		}
	}
}
