Skip to content

Commit

Permalink
refactor: update cdk cache interface based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ipcrm committed Dec 14, 2023
1 parent b4cc3ab commit cf85c30
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 69 deletions.
121 changes: 63 additions & 58 deletions cli/cdk/go/proto/v1/cdk.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/cdk/go/proto/v1/cdk_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions cli/cmd/cdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ func (c *cliState) ReadCache(ctx context.Context, in *cdk.ReadCacheRequest) (*cd

var data []byte
if !c.ReadCachedAsset(in.Key, &data) { // not expired
return &cdk.ReadCacheResponse{Miss: false, Data: data}, nil
return &cdk.ReadCacheResponse{Hit: true, Data: data}, nil
}
return &cdk.ReadCacheResponse{
Miss: true,
Hit: false,
Data: nil,
}, nil
}

Expand All @@ -84,9 +85,9 @@ func (c *cliState) WriteCache(ctx context.Context, in *cdk.WriteCacheRequest) (*
err := c.writeAssetToCache(in.Key, in.Expires.AsTime(), in.Data)
if err != nil {
msg := err.Error()
return &cdk.WriteCacheResult{Success: false, Msg: &msg}, nil
return &cdk.WriteCacheResult{Error: true, Message: msg}, nil
}
return &cdk.WriteCacheResult{Success: true}, nil
return &cdk.WriteCacheResult{Error: false, Message: ""}, nil
}

// Ping implements CDK.Ping
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/test_resources/cdk/go-component/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func app() error {
if err != nil {
return err
}
if !r.Success {
return fmt.Errorf("failed to write to cache: %s", *r.Msg)
if r.Error {
return fmt.Errorf("failed to write to cache: %s", r.Message)
}
return nil

Expand Down
17 changes: 13 additions & 4 deletions proto/v1/cdk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,31 @@ message HoneyventRequest {
int64 duration_ms = 4;
}

// WriteCacheRequest is used to submit data that should be written to cache, included its expiry
message WriteCacheRequest {
// name of the cache key to write
string key = 1;
bytes data = 2;
google.protobuf.Timestamp expires = 3;
}

// ReadCacheRequest is used to fetch data from the cache
message ReadCacheRequest {
// name of the cache key to read
string key = 1;
}

// ReadCacheResponse is the response type after a ReadCacheRequest is made
message ReadCacheResponse {
bool miss = 1;
optional bytes data = 2; // body is empty if cache miss
// hit is true when data was found, false otherwise
bool hit = 1;
// empty if cache miss (hit == false)
bytes data = 2;
}

// WriteCacheResult is the response type after a WriteCacheRequest is made
message WriteCacheResult {
bool success = 1;
optional string msg = 2; // error message is empty if success true
bool error = 1;
// message stores the error body if error == true, otherwise empty
string message = 2;
}

0 comments on commit cf85c30

Please sign in to comment.