mirror of
				https://github.com/owncast/owncast.git
				synced 2025-11-01 02:44:31 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			577 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			577 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package data
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"sync"
 | |
| )
 | |
| 
 | |
| var _cacheLock = sync.Mutex{}
 | |
| 
 | |
| // GetCachedValue will return a value for key from the cache.
 | |
| func (ds *Datastore) GetCachedValue(key string) ([]byte, error) {
 | |
| 	_cacheLock.Lock()
 | |
| 	defer _cacheLock.Unlock()
 | |
| 
 | |
| 	// Check for a cached value
 | |
| 	if val, ok := ds.cache[key]; ok {
 | |
| 		return val, nil
 | |
| 	}
 | |
| 
 | |
| 	return nil, errors.New(key + " not found in cache")
 | |
| }
 | |
| 
 | |
| // SetCachedValue will set a value for key in the cache.
 | |
| func (ds *Datastore) SetCachedValue(key string, b []byte) {
 | |
| 	_cacheLock.Lock()
 | |
| 	defer _cacheLock.Unlock()
 | |
| 
 | |
| 	ds.cache[key] = b
 | |
| }
 | 
