go-generics-cache icon indicating copy to clipboard operation
go-generics-cache copied to clipboard

Add a GetDefault method.

Open bn-jbowers opened this issue 9 months ago • 1 comments

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.

bn-jbowers avatar Sep 26 '23 15:09 bn-jbowers