mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 14:48:43 +05:00
used response cache in responder
This commit is contained in:
@@ -8,20 +8,25 @@ import (
|
||||
|
||||
var ErrNotFound = errors.New("NOT_FOUND")
|
||||
|
||||
type CacheItem struct {
|
||||
Value interface{}
|
||||
Err error
|
||||
}
|
||||
|
||||
type ResponseCache struct {
|
||||
ttl time.Duration
|
||||
cache map[string]interface{}
|
||||
cache map[string]*CacheItem
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func NewResponseCache(ttl time.Duration) *ResponseCache {
|
||||
return &ResponseCache{
|
||||
ttl: ttl,
|
||||
cache: make(map[string]interface{}),
|
||||
cache: make(map[string]*CacheItem),
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *ResponseCache) Cache(key string, item interface{}) {
|
||||
func (rc *ResponseCache) Cache(key string, item *CacheItem) {
|
||||
rc.mu.Lock()
|
||||
rc.cache[key] = item
|
||||
rc.mu.Unlock()
|
||||
@@ -33,7 +38,7 @@ func (rc *ResponseCache) Cache(key string, item interface{}) {
|
||||
}()
|
||||
}
|
||||
|
||||
func (rc *ResponseCache) Get(key string) (interface{}, error) {
|
||||
func (rc *ResponseCache) Get(key string) (*CacheItem, error) {
|
||||
rc.mu.RLock()
|
||||
defer rc.mu.RUnlock()
|
||||
item, ok := rc.cache[key]
|
||||
|
||||
Reference in New Issue
Block a user