mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	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
This commit is contained in:
		@@ -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 {
 | 
			
		||||
	case "memory":
 | 
			
		||||
		CacheInterval = Cfg.Section("cache").Key("INTERVAL").MustInt(60)
 | 
			
		||||
	case "redis", "memcache":
 | 
			
		||||
		CacheConn = strings.Trim(Cfg.Section("cache").Key("HOST").String(), "\" ")
 | 
			
		||||
	default:
 | 
			
		||||
		log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
 | 
			
		||||
	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")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user