func (c *Cache) Add(vcenter, section, i string, v interface{}) {
	if len(vcenter) == 0 || len(section) == 0 || len(i) == 0 || v == nil {
		return
	}
	switch typed := v.(type) {
	case string:
		c.add(vcenter, section, i, &typed)
	case []string:
		if len(typed) > 0 {
			c.add(vcenter, section, i, &typed)
		}
	case int32:
		c.add(vcenter, section, i, &typed)
	case types.ManagedObjectReference:
		c.add(vcenter, section, i, &(typed.Value))
	case types.ArrayOfManagedObjectReference:
		if len(typed.ManagedObjectReference) > 0 {
			c.add(vcenter, section, i, &(typed.ManagedObjectReference))
		}
	case types.ArrayOfTag:
		if len(typed.Tag) > 0 {
			c.add(vcenter, section, i, &(typed.Tag))
		}
	case types.ArrayOfGuestDiskInfo:
		if len(typed.GuestDiskInfo) > 0 {
			c.add(vcenter, section, i, &(typed.GuestDiskInfo))
		}
	case types.VirtualMachineConnectionState:
		c.add(vcenter, section, i, &typed)
	case types.VirtualMachinePowerState:
		c.add(vcenter, section, i, &typed)
	case types.HostSystemConnectionState:
		c.add(vcenter, section, i, &typed)
	case types.HostSystemPowerState:
		c.add(vcenter, section, i, &typed)
	case types.DVSTrafficShapingPolicy:
		c.add(vcenter, section, i, &typed)
	case types.ArrayOfVirtualDevice:
		c.add(vcenter, section, i, &typed)
	default:
		log.Printf("cache %s/%s: unhandled type %T for %s\n", vcenter, section, v, i)
	}
}
Add a value to the cache
package vsphere
import (
	"bytes"
	"log"
	"strings"
	"sync"
	"github.com/cblomart/vsphere-graphite/utils"
	"github.com/vmware/govmomi/vim25/types"
)
type Cache map[string]interface{}
var lock = sync.RWMutex{}
func index(vcenter, section, i string) string {
	var buffer bytes.Buffer
	_, err := buffer.WriteString(vcenter)
	if err != nil {
		return ""
	}
	_, err = buffer.WriteString("|")
	if err != nil {
		return ""
	}
	_, err = buffer.WriteString(section)
	if err != nil {
		return ""
	}
	_, err = buffer.WriteString("|")
	if err != nil {
		return ""
	}
	_, err = buffer.WriteString(i)
	if err != nil {
		return ""
	}
	return buffer.String()
}