Documentation ¶
Overview ¶
Package aememcache handles Put, Get etc to Datastore and provides caching by AppEngine's Memcache. How the cache is used is explained in the storagecache package's document.
Related document.
https://cloud.google.com/appengine/docs/standard/go/memcache/ https://godoc.org/go.mercari.io/datastore/dsmiddleware/storagecache
Example (HowToUse) ¶
package main import ( "context" "go.mercari.io/datastore/aedatastore" "go.mercari.io/datastore/dsmiddleware/aememcache" "google.golang.org/appengine" "google.golang.org/appengine/aetest" ) func appengineContext() (ctx context.Context, cancelFn func() error) { inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true, SuppressDevAppServerLog: true}) if err != nil { panic(err) } cancelFn = inst.Close r, err := inst.NewRequest("GET", "/", nil) if err != nil { panic(err) } ctx = appengine.NewContext(r) return } func main() { ctx, cancelFn := appengineContext() go cancelFn() client, err := aedatastore.FromContext(ctx) if err != nil { panic(err) } defer client.Close() mw := aememcache.New() client.AppendMiddleware(mw) }
Output:
Index ¶
- func New(opts ...CacheOption) interface{ ... }
- type CacheOption
- func WithCacheKey(f func(key datastore.Key) string) CacheOption
- func WithExcludeKinds(kinds ...string) CacheOption
- func WithExpireDuration(d time.Duration) CacheOption
- func WithIncludeKinds(kinds ...string) CacheOption
- func WithKeyFilter(f storagecache.KeyFilter) CacheOption
- func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) CacheOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(opts ...CacheOption) interface { datastore.Middleware storagecache.Storage }
New AE Memcache middleware creates & returns.
Types ¶
type CacheOption ¶ added in v0.15.0
type CacheOption interface {
Apply(*cacheHandler)
}
A CacheOption is an cache option for a AE Memcache middleware.
func WithCacheKey ¶ added in v0.15.0
func WithCacheKey(f func(key datastore.Key) string) CacheOption
WithCacheKey creates a ClientOption that specifies how to generate a cache key from datastore.Key.
func WithExcludeKinds ¶ added in v0.15.0
func WithExcludeKinds(kinds ...string) CacheOption
WithExcludeKinds creates a ClientOption that selects the Kind unspecified as the cache target.
func WithExpireDuration ¶ added in v0.15.0
func WithExpireDuration(d time.Duration) CacheOption
WithExpireDuration creates a ClientOption to expire at a specified time.
func WithIncludeKinds ¶ added in v0.15.0
func WithIncludeKinds(kinds ...string) CacheOption
WithIncludeKinds creates a ClientOption that selects the Kind specified as the cache target.
func WithKeyFilter ¶ added in v0.15.0
func WithKeyFilter(f storagecache.KeyFilter) CacheOption
WithKeyFilter creates a ClientOption that selects the Keys specified as the cache target.
func WithLogger ¶ added in v0.15.0
func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) CacheOption
WithLogger creates a ClientOption that uses the specified logger.