zhangqian
2023-09-23 14fc2f577e2c0b7b146c1a430e9438f317ad5b0c
service/cache_store.go
@@ -47,36 +47,36 @@
}
const (
   PlcCacheKey             = "plc:%v:%v" //plc:position:key
   PlcCacheKey             = "plc:%v:%v" //plc:channel:key
   CurrentTaskCacheKey     = "current_task"
   CurrentProgressCacheKey = "current_progress:%v"          //current_progress:position
   PlcCacheKeyUpdateTime   = "finish_number_update_time:%v" //finish_number_update_time:position
   CurrentProgressCacheKey = "current_progress:%v"          //current_progress:channel
   PlcCacheKeyUpdateTime   = "finish_number_update_time:%v" //finish_number_update_time:channel
)
func PlcCacheGet(position int, key string) (interface{}, bool) {
   return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, position, key))
func PlcCacheGet(channel int32, key string) (interface{}, bool) {
   return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, channel, key))
}
func PlcCacheSet(position int, key string, value interface{}) {
func PlcCacheSet(channel int32, key string, value interface{}) {
   if key == constvar.PlcCacheKeyFinishNumber {
      oldFinishNumber, exists := PlcCacheGet(position, key)
      oldFinishNumber, exists := PlcCacheGet(channel, key)
      if !exists || cast.ToInt(oldFinishNumber) != cast.ToInt(value) { //finishNumber有了变化,设置更新时间缓存
         FinishUpdateTimeSet(position, time.Now().Unix())
         FinishUpdateTimeSet(channel, time.Now().Unix())
      }
   }
   defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, position, key), value)
   defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, channel, key), value)
}
func FinishUpdateTimeGet(position int) interface{} {
   val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, position))
func FinishUpdateTimeGet(channel int32) interface{} {
   val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, channel))
   if ok {
      return val
   }
   return 0
}
func FinishUpdateTimeSet(position int, value interface{}) {
   defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, position), value)
func FinishUpdateTimeSet(channel int32, value interface{}) {
   defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, channel), value)
}
func TaskCacheSet(value *response.TaskData) {
@@ -94,17 +94,17 @@
   return nil, false
}
func ProgressCacheGet(position int) (*model.ProductionProgress, bool) {
   if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, position)); ok {
func ProgressCacheGet(channel int32) (*model.ProductionProgress, bool) {
   if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, channel)); ok {
      return v.(*model.ProductionProgress), ok
   }
   return nil, false
}
func ProgressCacheSet(position int, value *model.ProductionProgress) {
   defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, position), value)
func ProgressCacheSet(channel int32, value *model.ProductionProgress) {
   defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, channel), value)
}
func ProgressCacheUnset(position int) {
   defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, position))
func ProgressCacheUnset(channel int32) {
   defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, channel))
}