refs: conditional ref updates

Allow updating references if the old value matches the given one.