datastore: Index | Files

package storagecache

import ""

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.


Package Files

doc.go storagecache.go

func New Uses

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

New storage cache (interface) middleware creates & returns.

type CacheItem Uses

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

CacheItem is serialized by Storage.

type KeyFilter Uses

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 Uses

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

Options provides common option values for storage.

type Storage Uses

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.

Package storagecache imports 3 packages (graph) and is imported by 4 packages. Updated 2018-08-24. Refresh now. Tools for package owners.