2019-02-09 20:37:37 -05:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
2019-07-16 21:04:37 -04:00
|
|
|
|
2019-08-23 12:40:30 -04:00
|
|
|
_ "gitea.com/macaron/cache/memcache" // memcache plugin for cache
|
|
|
|
_ "gitea.com/macaron/cache/redis"
|
2019-02-09 20:37:37 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Cache represents cache settings
|
|
|
|
type Cache struct {
|
|
|
|
Adapter string
|
|
|
|
Interval int
|
|
|
|
Conn string
|
|
|
|
TTL time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// CacheService the global cache
|
|
|
|
CacheService *Cache
|
|
|
|
)
|
|
|
|
|
|
|
|
func newCacheService() {
|
|
|
|
sec := Cfg.Section("cache")
|
|
|
|
CacheService = &Cache{
|
|
|
|
Adapter: sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}),
|
|
|
|
}
|
|
|
|
switch CacheService.Adapter {
|
|
|
|
case "memory":
|
|
|
|
CacheService.Interval = sec.Key("INTERVAL").MustInt(60)
|
|
|
|
case "redis", "memcache":
|
|
|
|
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
|
|
|
|
default:
|
2019-04-02 03:48:31 -04:00
|
|
|
log.Fatal("Unknown cache adapter: %s", CacheService.Adapter)
|
2019-02-09 20:37:37 -05:00
|
|
|
}
|
|
|
|
CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour)
|
|
|
|
|
|
|
|
log.Info("Cache Service Enabled")
|
|
|
|
}
|