cache

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cache provides a client interceptor for caching of the Cloud Datastore.

Cached data is used only for the following non-transactional data retrieval and is saved when it retrieved from the datastore without existing in the cache.

  • Get
  • GetMulti

Cached data is deleted when data is updated or deleted, including transaction.

  • Put/PutMulti(when key is not IncompleteKey)
  • Delete/DeleteMulti
  • Mutation(Update, Upsert, Delete)

Even if changes are applied to the datastore, the cache deletion may fail. In that case, the data will be inconsistent until the datastore is rolled back or the cache is deleted.

Note that RunInTransaction does not roll back when cache deletion fails.

The advantage of using an interceptor is that can be used without changing the client of cloud.google.com/go/datastore. However, unlike packages that wrap the client like github.com/mjibson/goon, it's not possible to provide a mechanism such as calling methods without a key. In addition, it may not work correctly if the protobuf definitions for the Datastore is changed.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnaryClientInterceptor

func UnaryClientInterceptor(cacher Cacher) grpc.UnaryClientInterceptor

UnaryClientInterceptor returns a new unary client interceptor that caches gRPC calls of the Cloud Datastore using Cacher.

Example
datastore.NewClient(context.Background(), "my-project",
	option.WithGRPCDialOption(grpc.WithUnaryInterceptor(UnaryClientInterceptor(exampleCacher))),
)
Output:

Types

type Cacher

type Cacher interface {
	// GetMulti returns the values of the given keys as a slice of []byte.
	// The length of this slice must be the same as length of the keys.
	// If there are missing values, set corresponding elements to nil.
	// It returns nil when all values are missing.
	GetMulti(ctx context.Context, keys []*datastorepb.Key) [][]byte

	// SetMulti saves in the pair of keys and values for each element.
	// This method will be called even if ErrNoSuchEntity is returned by
	// the datastore client when uncached data is found.
	SetMulti(ctx context.Context, keys []*datastorepb.Key, values [][]byte)

	// DeleteMulti deletes values for the given keys. The error is used to
	// make the datastore call fail. Do not return an error if the key is
	// not found in the cache.
	DeleteMulti(ctx context.Context, keys []*datastorepb.Key) error
}

Cacher is the interface implemented by an object that manages the cache.

Directories

Path Synopsis
Package aememcache provides App Engine memcache cache that implements cache.Cacher interface.
Package aememcache provides App Engine memcache cache that implements cache.Cacher interface.
Package memory provides in-memory cache that implements cache.Cacher interface.
Package memory provides in-memory cache that implements cache.Cacher interface.
Package redis provides Redis cache that implements cache.Cacher interface.
Package redis provides Redis cache that implements cache.Cacher interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL