ISPN-2435 Cache#replace(key, old, new) method doesn't check old value on...

replacement for #1657, contains some (review ) fixes from Dan.