storagecache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package storagecache provides a mechanism for using various storage as datastore's cache. This package will not be used directly, but it will be used via aememcache or redicache.

This package automatically processes so that the cache state matches the Entity on Datastore.

The main problem is transactions. Do not read from cache under transaction. Under a transaction it should not be added to the cache until it is committed or rolled back.

In order to avoid troublesome bugs, under the transaction, Get, Put and Delete only record the Key, delete all caches related to the Key recorded when committed.

For now, no caching is made for the Entity that returned from the query. If you want to cache it, there is a way to query with KeysOnly first, and exec GetMulti next.

In all operations, the key target is determined by KeyFilter. In order to make consistency easy, we recommend using the same settings throughout the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(s Storage, opts *Options) datastore.Middleware

New storage cache (interface) middleware creates & returns.

Types

type CacheItem

type CacheItem struct {
	Key          datastore.Key
	PropertyList datastore.PropertyList
}

CacheItem is serialized by Storage.

type KeyFilter added in v0.16.0

type KeyFilter func(ctx context.Context, key datastore.Key) bool

KeyFilter represents a function that determines if the specified Key should be cached.

type Options added in v0.15.0

type Options struct {
	Logf    func(ctx context.Context, format string, args ...interface{})
	Filters []KeyFilter
}

Options provides common option values for storage.

type Storage

type Storage interface {
	SetMulti(ctx context.Context, is []*CacheItem) error
	// GetMulti returns slice of CacheItem of the same length as Keys of the argument.
	// If not in the dsmiddleware, the value of the corresponding element is nil.
	GetMulti(ctx context.Context, keys []datastore.Key) ([]*CacheItem, error)
	DeleteMulti(ctx context.Context, keys []datastore.Key) error
}

Storage is the abstraction of storage that holds the cache data.

Jump to

Keyboard shortcuts

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