cloud-datastore-interceptor

module
Version: 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

README

cloud-datastore-interceptor

GoDoc

Package github.com/DeNA/cloud-datastore-interceptor provides gRPC interceptors for Cloud Datastore(cloud.google.com/go/datastore).

Examples

In-Memory cache

This will use in-memory cache on Client.Get and Client.GetMulti.

opts := []option.ClientOption{
		option.WithGRPCDialOption(
			grpc.WithUnaryInterceptor(
				cache.UnaryClientInterceptor(memory.NewCache(1 * time.Minute)),
			),
		),
}
client, err := datastore.NewClient(ctx, projID, opts...)
Cache query results

cache.UnaryClientInterceptor does not use the cache for Query(e.g., Client.GetAll, Client.Run), but by using transform.QueryToLookupWithKeysOnly, it is transformed to gRPC equivalent to Client.GetMulti and the cache is used.

opts := []option.ClientOption{
		option.WithGRPCDialOption(
			grpc.WithChainUnaryInterceptor(
				transform.QueryToLookupWithKeysOnly(),
				cache.UnaryClientInterceptor(memory.NewCache(1 * time.Minute)),
			),
		),
}
client, err := datastore.NewClient(ctx, projID, opts...)
Redis cache

Same as In-Memory cache, but the backend is Redis using redisClient.

opts := []option.ClientOption{
		option.WithGRPCDialOption(
			grpc.WithUnaryInterceptor(
				cache.UnaryClientInterceptor(redis.NewCache(1 * time.Minute, redisClient)),
			),
		),
}
client, err := datastore.NewClient(ctx, projID, opts...)

Directories

Path Synopsis
Package cache provides a client interceptor for caching of the Cloud Datastore.
Package cache provides a client interceptor for caching of the Cloud Datastore.
aememcache
Package aememcache provides App Engine memcache cache that implements cache.Cacher interface.
Package aememcache provides App Engine memcache cache that implements cache.Cacher interface.
memory
Package memory provides in-memory cache that implements cache.Cacher interface.
Package memory provides in-memory cache that implements cache.Cacher interface.
redis
Package redis provides Redis cache that implements cache.Cacher interface.
Package redis provides Redis cache that implements cache.Cacher interface.
Package transform provides a client interceptor that transforms gRPC requests.
Package transform provides a client interceptor that transforms gRPC requests.

Jump to

Keyboard shortcuts

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