waymaker-client/go/cache.go

75 lines
2.2 KiB
Go

package waymaker
// Cache subsystem — TTL/eviction policy service (WaymakerCacheService).
//
// The server-side implementation is not yet complete; every call currently
// returns an "unimplemented" error from the server. The client surface
// matches the Rust client's minimal stub so callers can compile and wire
// up now, ready for when the server lands the first eviction policy.
//
// Entry points on *Client:
// - client.CacheAttachPolicy(ctx, bucket, policyID, params)
// - client.CacheDetachPolicy(ctx, bucket, policyID)
// - client.CacheStats(ctx, bucket)
import (
"context"
pb "git.awesomike.com/pub/waymaker-client/go/genpb/cache"
)
// CacheStats is returned by CacheStats.
type CacheStats struct {
// Raw proto response; fields will be populated when the server
// implementation lands.
Raw *pb.StatsResponse
}
// CacheAttachPolicy attaches an eviction policy to a bucket.
// NOTE: server currently returns Unimplemented.
func (c *Client) CacheAttachPolicy(ctx context.Context, bucket, policyID string, params map[string]string) error {
cc := c.cacheClient()
r, err := cc.AttachPolicy(ctx, &pb.AttachPolicyRequest{
Bucket: bucket,
PolicyId: policyID,
Params: params,
})
if err != nil {
return rpcErr(err)
}
if !r.GetSuccess() {
return serverErr(r.GetResultCode(), r.GetMessage())
}
return nil
}
// CacheDetachPolicy detaches the policy from a bucket.
// NOTE: server currently returns Unimplemented.
func (c *Client) CacheDetachPolicy(ctx context.Context, bucket string) error {
cc := c.cacheClient()
r, err := cc.DetachPolicy(ctx, &pb.DetachPolicyRequest{
Bucket: bucket,
})
if err != nil {
return rpcErr(err)
}
if !r.GetSuccess() {
return serverErr(r.GetResultCode(), r.GetMessage())
}
return nil
}
// CacheStats returns cache statistics for a bucket.
// NOTE: server currently returns Unimplemented.
func (c *Client) CacheStats(ctx context.Context, bucket string) (CacheStats, error) {
cc := c.cacheClient()
r, err := cc.Stats(ctx, &pb.StatsRequest{Bucket: bucket})
if err != nil {
return CacheStats{}, rpcErr(err)
}
if !r.GetSuccess() {
return CacheStats{}, serverErr(r.GetResultCode(), r.GetMessage())
}
return CacheStats{Raw: r}, nil
}