// Get checks local cache, then memcache, then datastore. Caches it if it's not in cache yet.
Get checks local cache, then memcache, then datastore. Caches it if it's not in cache yet.
// Get checks local cache then memcache then datastore . Caches it if it ' s not in cache yet .
func (c *Client) Get(ctx context.Context, key *datastore.Key, dst interface{}) error {
	v := reflect.ValueOf(dst)
	if v.Kind() != reflect.Ptr {
		return fmt.Errorf("dscache.Client.Get: dst must be a pointer")
	}
	found := false
	cKey := cacheKey(key)
	c.localCacheLock.RLock()
	if val, ok := c.localCache[cKey]; ok {
		setValue(key, v, val)
		found = true
	}
	c.localCacheLock.RUnlock()
	if !found {
		if buf, err := c.Cache.Get(cKey); err == nil {
			setValue(key, v, buf)
			c.putLocalCache(cKey, dst)
			found = true
		}
	}
	if !found {
		if err := c.DSClient.Get(ctx, key, dst); err != nil {
			return fmt.Errorf("dscache.Client.Get: failed datastore get %v", err)
		}
		if err := c.putCache(cKey, dst); err != nil {
			return fmt.Errorf("dscache.Client.Get: failed to put in cache %v", err)
		}
	}
	return nil
}
func ( c * Client ) Get ( ctx context . Context , key * datastore . Key , dst interface { } ) error { v := reflect . ValueOf ( dst ) if v . Kind ( ) != reflect . Ptr { return fmt . Errorf ( " " ) } found := false cKey := cacheKey ( key ) c . localCacheLock . RLock ( ) if val , ok := c . localCache [ cKey ] ; ok { setValue ( key , v , val ) found = true } c . localCacheLock . RUnlock ( ) if ! found { if buf , err := c . Cache . Get ( cKey ) ; err == nil { setValue ( key , v , buf ) c . putLocalCache ( cKey , dst ) found = true } } if ! found { if err := c . DSClient . Get ( ctx , key , dst ) ; err != nil { return fmt . Errorf ( " " , err ) } if err := c . putCache ( cKey , dst ) ; err != nil { return fmt . Errorf ( " " , err ) } } return nil }
Get checks local cache, then memcache, then datastore.
Get checks local cache then memcache then datastore .
// Check local cache first // Check redis cache // get from datastore