syntax = "proto3";

package distributed_cache;

message Isolation {
  enum CacheType {
    UNKNOWN_TYPE = 0;
    ACTION_CACHE = 1;
    CAS_CACHE = 2;
  }
  CacheType cache_type = 1;
  string remote_instance_name = 2;
}

message Key {
  string key = 1;
  int64 size_bytes = 2;
}

message ReadRequest {
  Isolation isolation = 4;
  reserved 1;
  Key key = 2;
  int64 offset = 3;
}

message ReadResponse {
  bytes data = 1;
}

message WriteRequest {
  Isolation isolation = 6;
  reserved 1;
  Key key = 2;
  bool finish_write = 3;
  bytes data = 4;

  // A node that this data should eventually be handed off to.
  // Clients should attempt to replicate this data when possible.
  string handoff_peer = 5;
}

message WriteResponse {
  int64 committed_size = 1;
}

message FindMissingRequest {
  Isolation isolation = 1;
  repeated Key key = 2;
}

message FindMissingResponse {
  repeated Key missing = 1;
}

message KV {
  Key key = 1;
  bytes value = 2;
}

message GetMultiRequest {
  Isolation isolation = 3;
  reserved 1;
  repeated Key key = 2;
}

message GetMultiResponse {
  repeated KV key_value = 1;
}

message HeartbeatRequest {
  string source = 1;
}

message HeartbeatResponse {}

service DistributedCache {
  rpc Read(ReadRequest) returns (stream ReadResponse);
  rpc Write(stream WriteRequest) returns (WriteResponse);
  rpc FindMissing(FindMissingRequest) returns (FindMissingResponse);
  rpc GetMulti(GetMultiRequest) returns (GetMultiResponse);
  rpc Heartbeat(HeartbeatRequest) returns (HeartbeatResponse);
}
