func (c *cache) GetAndLoad(key string, value interface{}, loader func() (interface{}, error)) (err error) {
	// if its in the cache return it
	err = c.backend.Get(key, value)
	if err == nil {
		return nil
	}

	// otherwise fetch & load using singleflight
	result, err := c.group.Do(key, func() (interface{}, error) {
		//fetch the value using the provided loader
		v, err := loader()
		if err != nil {
			return nil, fmt.Errorf("Error loading value for key (%s): %v", key, err)
		}

		// set the value in the backend
		err = c.backend.Set(key, v, c.expiration)
		if err != nil {
			// log the error and ignore it.
			if c.log != nil {
				c.log.Printf("Error setting value in cache for key (%s): %v", key, err)
			}
			// only return an error if we aren't configured to ignore them
			if !c.ignoreSetErrors {
				return nil, fmt.Errorf("Error setting value in cache for key (%s): %v", key, err)
			}
		}
		return v, nil
	})
	if err != nil {
		return err
	}

	SetValue(value, result)
	return nil
}
// GetAndLoad will fetch the value from the cache, if it is missing it will load it into cache and return it.
// Concurrent calls to GetAndLoad for the same key will wait for the initial call to load the object
// to prevent cache runs.
GetAndLoad will fetch the value from the cache, if it is missing it will load it into cache and return it.
Concurrent calls to GetAndLoad for the same key will wait for the initial call to load the object
to prevent cache runs.
// GetAndLoad will fetch the value from the cache if it is missing it will load it into cache and return it . // Concurrent calls to GetAndLoad for the same key will wait for the initial call to load the object // to prevent cache runs .
func (c *cache) GetAndLoad(key string, value interface{}, loader func() (interface{}, error)) (err error) {
	err = c.backend.Get(key, value)
	if err == nil {
		return nil
	}
	result, err := c.group.Do(key, func() (interface{}, error) {
		v, err := loader()
		if err != nil {
			return nil, fmt.Errorf("Error loading value for key (%s): %v", key, err)
		}
		err = c.backend.Set(key, v, c.expiration)
		if err != nil {
			if c.log != nil {
				c.log.Printf("Error setting value in cache for key (%s): %v", key, err)
			}
			if !c.ignoreSetErrors {
				return nil, fmt.Errorf("Error setting value in cache for key (%s): %v", key, err)
			}
		}
		return v, nil
	})
	if err != nil {
		return err
	}
	SetValue(value, result)
	return nil
}
func ( c * cache ) GetAndLoad ( key string , value interface { } , loader func ( ) ( interface { } , error ) ) ( err error ) { err = c . backend . Get ( key , value ) if err == nil { return nil } result , err := c . group . Do ( key , func ( ) ( interface { } , error ) { v , err := loader ( ) if err != nil { return nil , fmt . Errorf ( " " , key , err ) } err = c . backend . Set ( key , v , c . expiration ) if err != nil { if c . log != nil { c . log . Printf ( " " , key , err ) } if ! c . ignoreSetErrors { return nil , fmt . Errorf ( " " , key , err ) } } return v , nil } ) if err != nil { return err } SetValue ( value , result ) return nil }
GetAndLoad will fetch the value from the cache, if it is missing it will load it into cache and return it.
GetAndLoad will fetch the value from the cache if it is missing it will load it into cache and return it .
// if its in the cache return it // otherwise fetch & load using singleflight //fetch the value using the provided loader // set the value in the backend // log the error and ignore it. // only return an error if we aren't configured to ignore them