cache

package
v0.0.0-...-716bffc Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cache - This package provides operations related to cache. The Cache is injected into gRPC communication such as Get/Delete/Update regarding the exchange with Datastore. And is realized by rewriting the Request/Response in the middle. ... このパッケージではキャッシュに関する操作を提供します。 キャッシュはDatastoreとのやり取りに関して、取得・削除・更新などのgRPC通信にインジェクションされ、中間でリクエスト・レスポンスを書き換えることで実現します。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// GetMulti - get the cache.
	//              └── キャッシュを取得する
	// An array of Datastore keys is passed and the corresponding data is obtained.
	//    └── Datastoreのキーの配列が渡され、それに対応するデータを取得する
	// If a key that does not exist in the cache is passed, it must be filled with nil and len(items) must match len(keys).
	//    └── キャッシュに存在しないキーが渡された場合にはnilを詰め、len(items)がlen(keys)と一致している必要がある
	GetMulti(ctx context.Context, projectID string, keys []*datastore.Key) (items []*datastore.EntityResult, err error)

	// SetMulti - Set to cache
	//              └── キャッシュする
	// Since an array of Entity of Datastore is passed, those data are cached.
	//    └── datastoreのEntityの配列が渡されるので、それらのデータをキャッシュする。
	SetMulti(ctx context.Context, projectID string, items []*datastore.EntityResult) (err error)

	// DeleteMulti - Delete from cache.
	//                 └── キャッシュから削除する。
	// It is called when the cache is destroyed by updating or deleting.
	//    └── 更新や削除などでキャッシュを破棄する場合に呼ばれる。
	DeleteMulti(ctx context.Context, projectID string, keys []*datastore.Key) (err error)
}

Cache - Mechanism for caching data.

└── データをキャッシュする機構。

It works by passing the one that satisfies this interface to middleware.

└── このインターフェイスを満たしたものをmiddlewareに渡すことで動作する

type CachingModeFunc

type CachingModeFunc = func(
	ctx context.Context,
	method string,
	req,
	reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) CachingModeType

CachingModeFunc - function that controls cache

└── Cacheの制御を行う関数

type CachingModeType

type CachingModeType int

CachingModeType - control cache

└── Cacheの制御を行う
const (
	// CachingModeNever - never use cache (キャッシュを一切使わない)
	CachingModeNever CachingModeType = 0

	// CachingModeWriteOnly - only write to cache
	//                          └── キャッシュの書き込みのみを行う
	// Cache is written even if Cache Delete Timing None is used in Cache Delete Timing.
	//    └── CacheDeleteTimingにてCacheDeleteTiming_Noneを使用していた場合でも、キャッシュの書き込みを行う
	CachingModeWriteOnly CachingModeType = 1

	// CachingModeReadOnly - only read cache
	//                         └── キャッシュの読み取りのみを行う
	// Even if there is uncached data, new cache is not written.
	//    └── キャッシュされてないデータがあろうとも、新しくキャッシュの書き込みは行わない
	CachingModeReadOnly CachingModeType = 2

	// CachingModeReadWrite - read and write the cache
	//                          └── キャッシュの読み取りと書き込みを行う
	// Default behavior
	//    └── デフォルトの動作
	CachingModeReadWrite CachingModeType = 3
)

type DeleteTiming

type DeleteTiming int

DeleteTiming - Controls the cache deletion timing.

└── キャッシュの削除タイミングを制御する。
const (
	// DeleteTimingNone - Do not delete the cache.
	//                      └── キャッシュを削除しない。
	// It is not recommended because the cache may not be deleted even if operations such
	// as deletion and modification are performed, which may result in inconsistent data.
	//    └── 削除や変更などの操作を加えてもキャッシュが削除されず、データの整合性が取れなくなる恐れがあるため、非推奨。
	// Deprecated: Not recommended because the data integrity cannot be obtained.
	//    └── データの整合性が取れなくなるため非推奨
	DeleteTimingNone DeleteTiming = 0

	// DeleteTimingBeforeCommit - Execute cache deletion before issuing Commit.
	//                              └── Commitを発行する前にキャッシュの削除を実行する
	DeleteTimingBeforeCommit DeleteTiming = 1

	// DeleteTimingAfterCommit - Delete the cache after issuing Commit.
	//                             └── Commitを発行した後にキャッシュの削除を実行する
	DeleteTimingAfterCommit DeleteTiming = 2

	// DeleteTimingBeforeAndAfterCommit - Execute deletion before issuing Commit and twice after issuing Commit.
	//                                      └── Commitを発行する前と発行した後の2回に削除を実行する
	// Note that deletion is performed twice before commit and after commit,
	// and twice the normal query is sent to the cache.
	//    └── Commit前とCommit後の2回に削除が行われ、キャッシュに対して通常の倍のクエリが送信されるため注意
	DeleteTimingBeforeAndAfterCommit DeleteTiming = 3
)

type Middleware

type Middleware struct {

	// DeleteTiming - Timing to delete Cache.
	//                  └── Cacheの削除を行うタイミング。
	CacheDeleteTiming DeleteTiming
	// CachingModeFunc - A function that individually manages cache deletion and status.
	//                     └── Cacheの削除や状態を個別に管理する関数。
	CachingModeFunc CachingModeFunc
	Logger          *log.Logger
	// contains filtered or unexported fields
}

Middleware - Middleware that manages the cache.

└── キャッシュを管理するミドルウェア。

func NewMiddleware

func NewMiddleware(cache Cache) *Middleware

NewMiddleware - Initialize Middleware that caches Datastore operations.

└── Datastoreの操作をキャッシュするMiddlewareを初期化する

cache - It must be a structure that satisfies the Cache interface.

└── Cacheインターフェイスを満たす構造体である必要がある。

Operate the cache interface to realize the cache.

└── cacheインターフェイスを操作し、キャッシュを実現する

Default behavior:

  • cache is deleted before and after update operation
  • Cache all elements

デフォルト動作:

  • cacheは更新動作の前後で削除される
  • 全ての要素をキャッシュする

func (*Middleware) UnaryClientInterceptor

func (m *Middleware) UnaryClientInterceptor(
	ctx context.Context,
	method string, req,
	reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) (err error)

UnaryClientInterceptor - Called from Datastore gRPC.

└── DatastoreのgRPCから呼ばれる

type UnaryClientMethod

type UnaryClientMethod = string

UnaryClientMethod - Datastore invocation method

└── Datastoreの呼び出しメソッド
const (
	// UnaryClientMethodLookup - Called by inquiries such as Get and GetMulti
	//                             └── Get, GetMultiなどの問い合せにより呼ばれる
	UnaryClientMethodLookup UnaryClientMethod = "/google.datastore.v1.Datastore/Lookup"

	// UnaryClientMethodCommit - Called by queries such as Put, PutMulti, Delete, DeleteMulti, Mutate, etc.
	//                             └── Put, PutMulti, Delete, DeleteMulti, Mutateなどの問い合わせにより呼ばれる
	UnaryClientMethodCommit UnaryClientMethod = "/google.datastore.v1.Datastore/Commit"
)

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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