@Override
	public CASResponse cas(String key, Object value, int ttlSec, long cas, 
			long timeoutMiliSec) throws TimeoutException, MemcachedException {
		validateKey(key);
		
		try {
			StringBuilder sb = new StringBuilder();

			byte valueBytes[] = null;
			int flag = -1;

			if (value instanceof String) {
				String arg = (String) value;
				valueBytes = arg.getBytes(charset);
				flag = FLAGS_GENRIC_STRING;
			} else {
				valueBytes = getObjectBytes(value);
				flag = FLAGS_GENRIC_OBJECT;
			}

			//cas <key> <flags> <exptime> <bytes> <cas unique> [noreply]\r\n
			sb.append("cas ").append(key).append(" ").append(flag);
			sb.append(" ").append(ttlSec).append(" ").append(valueBytes.length);
			sb.append(" ").append(cas).append("\r\n");
			sb.append(new String(valueBytes, charset));
			sb.append("\r\n");

			String res = sendCmdOut(key, sb.toString());
			if (res == null) {
				throw new TimeoutException("we got a null reply!");
			}
			if (res.equals("STORED")) {
				return CASResponse.OK;
			} else if (res.equals("NOT_STORED")) {
				return CASResponse.NOT_STORED;
			} else if (res.equals("EXISTS")) {
				return CASResponse.EXISTS;
			} else if (res.equals("NOT_FOUND")) {
				return CASResponse.NOT_FOUND;
			} else {
				logger.warning("Unknown res: " + res);
				return CASResponse.ERROR;
			}
		} catch (TimeoutException ex) {
			throw ex;
		} catch (Exception ex) {
			throw new MemcachedException("We had error " + ex);
		}
	}