Compare commits

...

2 Commits

Author SHA1 Message Date
fc1af9f4a1 Memo marks itself as valid on update 2024-09-10 16:45:17 -04:00
baad6aa227 Memo.Invalidate zeros out the held value automatically
InvalidateTo is no longer needed
2024-09-10 16:45:17 -04:00

View File

@ -20,6 +20,7 @@ func NewMemo[T any] (update func () T) Memo[T] {
func (this *Memo[T]) Value () T {
if !this.valid {
this.cache = this.update()
this.valid = true
}
return this.cache
}
@ -27,13 +28,8 @@ func (this *Memo[T]) Value () T {
// Invalidate marks the Memo's value as invalid, which will cause it to be
// updated the next time Value is called.
func (this *Memo[T]) Invalidate () {
var zero T
this.cache = zero
this.valid = false
}
// InvalidateTo invalidates the Memo and sets its value. The new value will be
// entirely inaccessible. This is only intended to be used for setting a
// reference to nil
func (this *Memo[T]) InvalidateTo (value T) {
this.Invalidate()
this.cache = value
}