@@ -65,13 +65,12 @@ func (c *SSEClient) Connect(environment string) error {
6565 // and subscribe to that event
6666 switch cfMsg .Event {
6767 case dto .SseDeleteEvent :
68- go func () {
68+ go func (identifier string ) {
6969 c .cache .Remove (dto.Key {
7070 Type : dto .KeyFeature ,
71- Name : cfMsg . Identifier ,
71+ Name : identifier ,
7272 })
73- }()
74-
73+ }(cfMsg .Identifier )
7574 case dto .SsePatchEvent , dto .SseCreateEvent :
7675 fallthrough
7776 default :
@@ -86,16 +85,42 @@ func (c *SSEClient) Connect(environment string) error {
8685 if response .JSON200 != nil {
8786 c .cache .Set (dto.Key {
8887 Type : dto .KeyFeature ,
89- Name : cfMsg . Identifier ,
88+ Name : identifier ,
9089 }, * response .JSON200 .Convert ())
9190 }
9291 }(environment , cfMsg .Identifier )
9392 }
9493 case dto .KeySegment :
9594 // need open client spec change
95+ switch cfMsg .Event {
96+ case dto .SseDeleteEvent :
97+ go func (identifier string ) {
98+ c .cache .Remove (dto.Key {
99+ Type : dto .KeySegment ,
100+ Name : identifier ,
101+ })
102+ }(cfMsg .Identifier )
103+ case dto .SsePatchEvent , dto .SseCreateEvent :
104+ fallthrough
105+ default :
106+ go func (env , identifier string ) {
107+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 60 )
108+ defer cancel ()
109+ response , err := c .api .GetSegmentByIdentifierWithResponse (ctx , env , identifier )
110+ if err != nil {
111+ c .logger .Errorf ("error while pulling segment, err: %s" , err .Error ())
112+ return
113+ }
114+ if response .JSON200 != nil {
115+ c .cache .Set (dto.Key {
116+ Type : dto .KeySegment ,
117+ Name : identifier ,
118+ }, response .JSON200 .Convert ())
119+ }
120+ }(environment , cfMsg .Identifier )
121+ }
96122 }
97123 }
98-
99124 })
100125 if err != nil {
101126 c .logger .Errorf ("Error: %s" , err .Error ())
0 commit comments