Skip to content

Commit

Permalink
增加移除Context
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 15, 2024
1 parent 9777a4c commit e908a58
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions asyncLocal/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ func SetContextIfNotExists[T any](key string, getValFunc func() T) {
routineContext.Set(mVal)
}
}

// Remove 移除缓存
func Remove[T any](key string) {
var t T
key = fastReflect.PointerOf(t).ReflectTypeString + "_" + key
if mVal := routineContext.Get(); mVal != nil {
delete(mVal, key)
routineContext.Set(mVal)
}
}

0 comments on commit e908a58

Please sign in to comment.