[优化] 优化缓存

This commit is contained in:
PandaX
2023-10-17 14:39:01 +08:00
parent 5db1db8289
commit 10b98df33c
17 changed files with 158 additions and 85 deletions

View File

@@ -57,6 +57,18 @@ func init() {
DeviceShadowInstance = shadow
}
func InitDeviceShadow(deviceName, ProductId string) Device {
device, err := DeviceShadowInstance.GetDevice(deviceName)
if err == UnknownDeviceErr {
attributes := make(map[string]DevicePoint)
telemetry := make(map[string]DevicePoint)
device = NewDevice(deviceName, ProductId, attributes, telemetry)
DeviceShadowInstance.AddDevice(device)
//shadow.DeviceShadowInstance.SetDeviceTTL()
}
return device
}
func (d *deviceShadow) AddDevice(device Device) (err error) {
if _, ok := d.m.Load(device.Name); ok {
return DeviceRepeatErr