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

has there any updates to this? can we now do upsert_with_cas? or is cas on upsert still ignored?

No change. sdk-rfcs/rfc/0053-sdk3-crud.md at master · couchbaselabs/sdk-rfcs · GitHub
There is no cas in UpsertOptions.
couchbase-php-client/Couchbase/UpsertOptions.php at main · couchbase/couchbase-php-client · GitHub