diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-02-10 09:37:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-10 09:37:37 +0800 |
commit | 820e28c9044bbd9d398dd1617323665bb0935e13 (patch) | |
tree | 67f57519600b6f7a11c695af7d72728636590456 /modules/setting/cache.go | |
parent | 9e8cc3b18da7438b315676686d6552926cc2965a (diff) | |
download | gitea-820e28c9044bbd9d398dd1617323665bb0935e13.tar.gz gitea-820e28c9044bbd9d398dd1617323665bb0935e13.zip |
Split setting.go as multiple files (#6014)
* split setting.go as multiple files
* fix comments
Diffstat (limited to 'modules/setting/cache.go')
-rw-r--r-- | modules/setting/cache.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/setting/cache.go b/modules/setting/cache.go new file mode 100644 index 0000000000..cbe73cf4e3 --- /dev/null +++ b/modules/setting/cache.go @@ -0,0 +1,43 @@ +// 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" +) + +// 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: + log.Fatal(4, "Unknown cache adapter: %s", CacheService.Adapter) + } + CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour) + + log.Info("Cache Service Enabled") +} |