2024-02-03 14:18:37 +00:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/patrickmn/go-cache"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RepositoryInformation struct {
|
|
|
|
// Headers to include in every response
|
|
|
|
Headers map[string]string
|
2024-02-03 14:39:31 +00:00
|
|
|
|
|
|
|
CNAME string
|
2024-02-03 14:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func repoInfoKey(owner, name string) string {
|
|
|
|
return owner + ":" + name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CacheContext) GetRepositoryInformation(owner, repoName string) *RepositoryInformation {
|
|
|
|
data, found := c.RepositoryInformationCache.Get(repoInfoKey(owner, repoName))
|
|
|
|
if !found {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
typedData := data.(RepositoryInformation)
|
|
|
|
return &typedData
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CacheContext) SetRepositoryInformation(owner, repoName string, info RepositoryInformation) {
|
|
|
|
c.RepositoryInformationCache.Set(
|
|
|
|
repoInfoKey(owner, repoName),
|
|
|
|
info,
|
|
|
|
cache.DefaultExpiration,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeRepoInfoCache() cache.Cache {
|
|
|
|
return *cache.New(24*time.Hour, 12*time.Hour)
|
|
|
|
}
|