40 lines
818 B
Go
40 lines
818 B
Go
package context
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.polynom.me/rio/internal/gitea"
|
|
"github.com/patrickmn/go-cache"
|
|
)
|
|
|
|
type RepositoryPathInformation struct {
|
|
Repository gitea.Repository
|
|
Path string
|
|
}
|
|
|
|
func pathInfoKey(domain, path string) string {
|
|
return domain + "/" + path
|
|
}
|
|
|
|
func (c *CacheContext) GetRepositoryPath(domain, path string) *RepositoryPathInformation {
|
|
data, found := c.RepositoryPathCache.Get(pathInfoKey(domain, path))
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
typedData := data.(RepositoryPathInformation)
|
|
return &typedData
|
|
}
|
|
|
|
func (c *CacheContext) SetRepositoryPath(domain, path string, info RepositoryPathInformation) {
|
|
c.RepositoryPathCache.Set(
|
|
pathInfoKey(domain, path),
|
|
info,
|
|
cache.DefaultExpiration,
|
|
)
|
|
}
|
|
|
|
func MakeRepoPathCache() cache.Cache {
|
|
return *cache.New(24*time.Hour, 12*time.Hour)
|
|
}
|