data/cache.go
func (s *Cache) Add(key string, value interface{}) error {
	lckStatus := s.removeExpired()

	i := &cacheItem{
		expireAt: time.Now().Add(s.lifetime),
		lifetime: s.lifetime,
		value:    value,
	}

	if lckStatus == raiqub.ReadLocked {
		s.RUnlock()
		s.Lock()
	}
	defer s.Unlock()

	if _, ok := s.values[key]; ok {
		return raiqub.DuplicatedKeyError(key)
	}

	s.values[key] = i
	return nil
}
func (s *Cache) Add(key string, value interface{}) error {
	lckStatus := s.removeExpired()

	i := &cacheItem{
		expireAt: time.Now().Add(s.lifetime),
		lifetime: s.lifetime,
		value:    value,
	}

	if lckStatus == raiqub.ReadLocked {
		s.RUnlock()
		s.Lock()
	}
	defer s.Unlock()

	if _, ok := s.values[key]; ok {
		return raiqub.DuplicatedKeyError(key)
	}

	s.values[key] = i
	return nil
}
func ( s * Cache ) Add ( key string , value interface { } ) error { lckStatus := s . removeExpired ( ) i := & cacheItem { expireAt : time . Now ( ) . Add ( s . lifetime ) , lifetime : s . lifetime , value : value , } if lckStatus == raiqub . ReadLocked { s . RUnlock ( ) s . Lock ( ) } defer s . Unlock ( ) if _ , ok := s . values [ key ] ; ok { return raiqub . DuplicatedKeyError ( key ) } s . values [ key ] = i return nil }
// Add adds a new key:value to current Cache instance.
//
// Errors:
// DuplicatedKeyError when requested key already exists.
Add adds a new key : value to current Cache instance . Errors : DuplicatedKeyError when requested key already exists .