本站源代码
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

47 lines
1.1KB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "strings"
  7. "time"
  8. "code.gitea.io/gitea/modules/log"
  9. _ "gitea.com/macaron/cache/memcache" // memcache plugin for cache
  10. _ "gitea.com/macaron/cache/redis"
  11. )
  12. // Cache represents cache settings
  13. type Cache struct {
  14. Adapter string
  15. Interval int
  16. Conn string
  17. TTL time.Duration
  18. }
  19. var (
  20. // CacheService the global cache
  21. CacheService *Cache
  22. )
  23. func newCacheService() {
  24. sec := Cfg.Section("cache")
  25. CacheService = &Cache{
  26. Adapter: sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}),
  27. }
  28. switch CacheService.Adapter {
  29. case "memory":
  30. CacheService.Interval = sec.Key("INTERVAL").MustInt(60)
  31. case "redis", "memcache":
  32. CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
  33. default:
  34. log.Fatal("Unknown cache adapter: %s", CacheService.Adapter)
  35. }
  36. CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour)
  37. log.Info("Cache Service Enabled")
  38. }
上海开阖软件有限公司 沪ICP备12045867号-1