fn cas()

in src/entrystore/src/seg/memcache.rs [287:342]


    fn cas(&mut self, cas: &Cas) -> Response {
        // duration of zero is treated as no expiry. as we have
        // no way of checking the cas value without performing a cas
        // and checking the result, setting the shortest possible ttl
        // results in nearly immediate expiry
        let ttl = cas.ttl().get().unwrap_or(1);

        let ttl = if ttl < 0 {
            Duration::from_secs(0)
        } else {
            Duration::from_secs(ttl as u64)
        };

        if let Ok(s) = std::str::from_utf8(cas.value()) {
            if let Ok(v) = s.parse::<u64>() {
                match self.data.cas(
                    cas.key(),
                    v,
                    Some(&cas.flags().to_be_bytes()),
                    ttl,
                    cas.cas() as u32,
                ) {
                    Ok(_) => Response::stored(cas.noreply()),
                    Err(SegError::NotFound) => Response::not_found(cas.noreply()),
                    Err(SegError::Exists) => Response::exists(cas.noreply()),
                    Err(_) => Response::error(),
                }
            } else {
                match self.data.cas(
                    cas.key(),
                    cas.value(),
                    Some(&cas.flags().to_be_bytes()),
                    ttl,
                    cas.cas() as u32,
                ) {
                    Ok(_) => Response::stored(cas.noreply()),
                    Err(SegError::NotFound) => Response::not_found(cas.noreply()),
                    Err(SegError::Exists) => Response::exists(cas.noreply()),
                    Err(_) => Response::error(),
                }
            }
        } else {
            match self.data.cas(
                cas.key(),
                cas.value(),
                Some(&cas.flags().to_be_bytes()),
                ttl,
                cas.cas() as u32,
            ) {
                Ok(_) => Response::stored(cas.noreply()),
                Err(SegError::NotFound) => Response::not_found(cas.noreply()),
                Err(SegError::Exists) => Response::exists(cas.noreply()),
                Err(_) => Response::error(),
            }
        }
    }