go-generics-cache
go-generics-cache copied to clipboard
Add a GetDefault method.
This adds a GetDefault method, which will either return the value in the cache, or if it is not present, set it with the passed-in value, returning whichever value ends up in the cache.
This must be done inside the cache because calling .Get, then .Set if the value is not present, is a TOCTOU (Time Of Check to Time Of Use) problem; something else may have set that value in the meantime. Only the cache can perform this operation atomically and safely.