Add commit count caching (#2774)
* Add commit count caching * Small refactoring * Add different key prefix for refs and commits * Add configuratuion option to allow to change caching time or disable it
This commit is contained in:
parent
3ab580c8d6
commit
eca05b09aa
10 changed files with 153 additions and 28 deletions
|
@ -325,11 +325,6 @@ var (
|
|||
// Time settings
|
||||
TimeFormat string
|
||||
|
||||
// Cache settings
|
||||
CacheAdapter string
|
||||
CacheInterval int
|
||||
CacheConn string
|
||||
|
||||
// Session settings
|
||||
SessionConfig session.Options
|
||||
CSRFCookieName = "_csrf"
|
||||
|
@ -1295,16 +1290,33 @@ func NewXORMLogService(disableConsole bool) {
|
|||
}
|
||||
}
|
||||
|
||||
// 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() {
|
||||
CacheAdapter = Cfg.Section("cache").Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
|
||||
switch CacheAdapter {
|
||||
case "memory":
|
||||
CacheInterval = Cfg.Section("cache").Key("INTERVAL").MustInt(60)
|
||||
case "redis", "memcache":
|
||||
CacheConn = strings.Trim(Cfg.Section("cache").Key("HOST").String(), "\" ")
|
||||
default:
|
||||
log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
|
||||
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:
|
||||
log.Fatal(4, "Unknown cache adapter: %s", CacheService.Adapter)
|
||||
}
|
||||
CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour)
|
||||
|
||||
log.Info("Cache Service Enabled")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue