You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }