summaryrefslogtreecommitdiffstats
path: root/modules/setting/setting.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-10-26 04:37:33 +0300
committerLunny Xiao <xiaolunwen@gmail.com>2017-10-26 09:37:33 +0800
commiteca05b09aa269dda1309ee77ac750e29e71c3fd3 (patch)
tree8f5a4aa5c7da0de3e6c2a16f8a567b0b1b0c758b /modules/setting/setting.go
parent3ab580c8d6b8a2c063d848f8e3002347c9e5cebb (diff)
downloadgitea-eca05b09aa269dda1309ee77ac750e29e71c3fd3.tar.gz
gitea-eca05b09aa269dda1309ee77ac750e29e71c3fd3.zip
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
Diffstat (limited to 'modules/setting/setting.go')
-rw-r--r--modules/setting/setting.go32
1 files changed, 22 insertions, 10 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 9787e09280..6c89381f3b 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -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 {
+ sec := Cfg.Section("cache")
+ CacheService = &Cache{
+ Adapter: sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}),
+ }
+ switch CacheService.Adapter {
case "memory":
- CacheInterval = Cfg.Section("cache").Key("INTERVAL").MustInt(60)
+ CacheService.Interval = sec.Key("INTERVAL").MustInt(60)
case "redis", "memcache":
- CacheConn = strings.Trim(Cfg.Section("cache").Key("HOST").String(), "\" ")
+ CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
default:
- log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
+ log.Fatal(4, "Unknown cache adapter: %s", CacheService.Adapter)
}
+ CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour)
log.Info("Cache Service Enabled")
}