mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-28 00:17:34 +02:00
cache : add cache service (#457)
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
parent
8a9cb0f803
commit
dccc7cd2ff
46 changed files with 1837 additions and 587 deletions
34
cache/grpc.go
vendored
Normal file
34
cache/grpc.go
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
//go:generate protoc -I ../internal/grpc/cache/ --go_out=plugins=grpc:../internal/grpc/cache/ ../internal/grpc/cache/cache.proto
|
||||
|
||||
package cache // import "github.com/pomerium/pomerium/cache"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/grpc/cache"
|
||||
"github.com/pomerium/pomerium/internal/telemetry/trace"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// Get retrieves a key the cache store and returns the value, if found.
|
||||
func (c *Cache) Get(ctx context.Context, in *cache.GetRequest) (*cache.GetReply, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "cache.grpc.Get")
|
||||
defer span.End()
|
||||
exists, value, err := c.cache.Get(ctx, in.GetKey())
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Unknown, "cache.grpc.Get error: %v", err)
|
||||
}
|
||||
return &cache.GetReply{Exists: exists, Value: value}, nil
|
||||
}
|
||||
|
||||
// Set persists a key value pair in the cache store.
|
||||
func (c *Cache) Set(ctx context.Context, in *cache.SetRequest) (*cache.SetReply, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "cache.grpc.Set")
|
||||
defer span.End()
|
||||
err := c.cache.Set(ctx, in.GetKey(), in.GetValue())
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Unknown, "cache.grpc.Set error: %v", err)
|
||||
}
|
||||
return &cache.SetReply{}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue