How to implement upsert-with-cas now?

I saw the cas method of UpsertOptions was removed since 3.1.2, I use this method in my project, so how to implement a same function as upsert-with-cas now? Currently I will use replace first, if it throws a DocumentNotFoundException, then try insert next. But this is really complicated, I have to use upsert, replace and insert in a method. Is there any better implemention I can try?

If you want to ensure optimistic locking :

  • if you don’t have a CAS, the only possibility is insert.
  • if you do have a CAS, the only possibility is replace.

If I’m not mistaken, a CAS option on Upsert was ignored. Which would give a false sense of providing optimistic locking. See https://issues.couchbase.com/browse/DOC-6218