Documentation

Overview

    Package cache provides cache service.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Cache

    type Cache struct {
    	// contains filtered or unexported fields
    }

      Cache represents key-value cache.

      func New

      func New(c Config) (*Cache, error)

        New creates new Cache for Config.

        func (*Cache) Get

        func (c *Cache) Get(ctx context.Context, req *cachepb.GetReq) (*cachepb.GetResp, error)

          Get gets key-value for requested key. It returns codes.NotFound if value not found in cache.

          func (*Cache) Put

          func (c *Cache) Put(ctx context.Context, req *cachepb.PutReq) (*cachepb.PutResp, error)

            Put puts new key-value pair in memcache (always; i.e. overwrite existing one) and cloud cache (if gcs is configured, and new value is put). It returns error if it fails to put cache in cloud storage.

            type Client

            type Client struct {
            	// contains filtered or unexported fields
            }

              Client is a client to access cache service via gRPC.

              func NewClient

              func NewClient(ctx context.Context, address string, opts ...grpc.DialOption) Client

                NewClient creates new client to access cache service serving on address. cache service will be sharded by key.

                func (Client) Close

                func (c Client) Close() error

                  Close releases the resources used by the client.

                  func (Client) Get

                  func (c Client) Get(ctx context.Context, in *pb.GetReq, opts ...grpc.CallOption) (*pb.GetResp, error)

                    Get gets key-value data for requested key.

                    func (Client) Put

                    func (c Client) Put(ctx context.Context, in *pb.PutReq, opts ...grpc.CallOption) (*pb.PutResp, error)

                      Put puts new key-value data. If no key-value is given, do nothing.

                      type Config

                      type Config struct {
                      	// MaxBytes is maximum number of bytes used for cache.
                      	MaxBytes int64
                      
                      	Bucket *storage.BucketHandle
                      }

                        Config is a configuration for Cache.

                        type LocalClient

                        type LocalClient struct {
                        	pb.CacheServiceServer
                        }

                          LocalClient is an adaptor to make CacheServiceServer as CacheServiceClient, ignoring any grpc.CallOption. TODO: use localhost server? https://github.com/grpc/grpc-go/issues/520

                          func (LocalClient) Get

                          func (c LocalClient) Get(ctx context.Context, in *pb.GetReq, opts ...grpc.CallOption) (*pb.GetResp, error)

                          func (LocalClient) Put

                          func (c LocalClient) Put(ctx context.Context, in *pb.PutReq, opts ...grpc.CallOption) (*pb.PutResp, error)

                          Directories

                          Path Synopsis
                          Package gcs provides cache service by google cloud storage.
                          Package gcs provides cache service by google cloud storage.
                          Package redis provides cache service by redis (cloud memorystore).
                          Package redis provides cache service by redis (cloud memorystore).