mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 19:45:25 +01:00 
			
		
		
		
	* Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2020 The Xorm Authors. All rights reserved.
 | |
| // Use of this source code is governed by a BSD-style
 | |
| // license that can be found in the LICENSE file.
 | |
| 
 | |
| package caches
 | |
| 
 | |
| import "sync"
 | |
| 
 | |
| type Manager struct {
 | |
| 	cacher             Cacher
 | |
| 	disableGlobalCache bool
 | |
| 
 | |
| 	cachers    map[string]Cacher
 | |
| 	cacherLock sync.RWMutex
 | |
| }
 | |
| 
 | |
| func NewManager() *Manager {
 | |
| 	return &Manager{
 | |
| 		cachers: make(map[string]Cacher),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // SetDisableGlobalCache disable global cache or not
 | |
| func (mgr *Manager) SetDisableGlobalCache(disable bool) {
 | |
| 	if mgr.disableGlobalCache != disable {
 | |
| 		mgr.disableGlobalCache = disable
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (mgr *Manager) SetCacher(tableName string, cacher Cacher) {
 | |
| 	mgr.cacherLock.Lock()
 | |
| 	mgr.cachers[tableName] = cacher
 | |
| 	mgr.cacherLock.Unlock()
 | |
| }
 | |
| 
 | |
| func (mgr *Manager) GetCacher(tableName string) Cacher {
 | |
| 	var cacher Cacher
 | |
| 	var ok bool
 | |
| 	mgr.cacherLock.RLock()
 | |
| 	cacher, ok = mgr.cachers[tableName]
 | |
| 	mgr.cacherLock.RUnlock()
 | |
| 	if !ok && !mgr.disableGlobalCache {
 | |
| 		cacher = mgr.cacher
 | |
| 	}
 | |
| 	return cacher
 | |
| }
 | |
| 
 | |
| // SetDefaultCacher set the default cacher. Xorm's default not enable cacher.
 | |
| func (mgr *Manager) SetDefaultCacher(cacher Cacher) {
 | |
| 	mgr.cacher = cacher
 | |
| }
 | |
| 
 | |
| // GetDefaultCacher returns the default cacher
 | |
| func (mgr *Manager) GetDefaultCacher() Cacher {
 | |
| 	return mgr.cacher
 | |
| }
 |