datastore: Index | Examples | Files

package localcache

import ""

Package localcache handles Put, Get etc to Datastore and provides caching by machine local memory. How the cache is used is explained in the storagecache package's document.

The local cache can not be deleted from other machines. Therefore, if the cache holding period becomes long, there is a possibility that the data is old. As a countermeasure, we recommend keeping the lifetime of the cache as long as processing one request.


ctx := context.Background()
client, err := clouddatastore.FromContext(ctx)
if err != nil {
defer client.Close()
defer testutils.CleanUpAllEntities(ctx, client)

mw := localcache.New()



Package Files

doc.go localcache.go option.go

type CacheHandler Uses

type CacheHandler interface {

    HasCache(key datastore.Key) bool
    DeleteCache(ctx context.Context, key datastore.Key)
    CacheKeys() []string
    CacheLen() int

CacheHandler abstracts cache operations to Storage.

func New Uses

func New(opts ...CacheOption) CacheHandler

New in-memory localcache middleware creates and returns.

type CacheOption Uses

type CacheOption interface {

A CacheOption is an option for cache.

func WithExcludeKinds Uses

func WithExcludeKinds(kinds ...string) CacheOption

WithExcludeKinds creates a ClientOption that selects the Kind unspecified as the cache target.

func WithExpireDuration Uses

func WithExpireDuration(d time.Duration) CacheOption

WithExpireDuration creates a ClientOption to expire at a specified time.

func WithIncludeKinds Uses

func WithIncludeKinds(kinds ...string) CacheOption

WithIncludeKinds creates a ClientOption that selects the Kind specified as the cache target.

func WithKeyFilter Uses

func WithKeyFilter(f storagecache.KeyFilter) CacheOption

WithKeyFilter creates a ClientOption that selects the Keys specified as the cache target.

func WithLogger Uses

func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) CacheOption

WithLogger creates a ClientOption that uses the specified logger.

Package localcache imports 5 packages (graph) and is imported by 2 packages. Updated 2018-07-30. Refresh now. Tools for package owners.