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 990B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. )
  10. // Cache represents cache settings
  11. type Cache struct {
  12. Adapter string
  13. Interval int
  14. Conn string
  15. TTL time.Duration
  16. }
  17. var (
  18. // CacheService the global cache
  19. CacheService *Cache
  20. )
  21. func newCacheService() {
  22. sec := Cfg.Section("cache")
  23. CacheService = &Cache{
  24. Adapter: sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}),
  25. }
  26. switch CacheService.Adapter {
  27. case "memory":
  28. CacheService.Interval = sec.Key("INTERVAL").MustInt(60)
  29. case "redis", "memcache":
  30. CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
  31. default:
  32. log.Fatal("Unknown cache adapter: %s", CacheService.Adapter)
  33. }
  34. CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour)
  35. log.Info("Cache Service Enabled")
  36. }