README.md: Remove the unprotected change example since it would actually need external synchronization
This commit is contained in:
parent
dd1ed0ba63
commit
96426d0c5b
23
README.md
23
README.md
|
@ -75,29 +75,6 @@ func main() {
|
||||||
foo := x.(*MyStruct)
|
foo := x.(*MyStruct)
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
// If you store a reference type like a pointer, slice, map or channel, you
|
|
||||||
// do not need to run Set if you modify the underlying data. The cached
|
|
||||||
// reference points to the same memory, so if you modify a struct whose
|
|
||||||
// pointer you've stored in the cache, retrieving that pointer with Get will
|
|
||||||
// point you to the same data:
|
|
||||||
foo := &MyStruct{Num: 1}
|
|
||||||
c.Set("foo", foo, cache.DefaultExpiration)
|
|
||||||
// ...
|
|
||||||
x, _ := c.Get("foo")
|
|
||||||
foo := x.(*MyStruct)
|
|
||||||
fmt.Println(foo.Num)
|
|
||||||
// ...
|
|
||||||
foo.Num++
|
|
||||||
// ...
|
|
||||||
x, _ := c.Get("foo")
|
|
||||||
foo := x.(*MyStruct)
|
|
||||||
foo.Println(foo.Num)
|
|
||||||
|
|
||||||
// will print:
|
|
||||||
// 1
|
|
||||||
// 2
|
|
||||||
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue