Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchFinishFunc ¶ added in v0.4.0
type BatchFinishFunc func(ResultMap)
BatchFinishFunc finishes the tracing for the BatchFunction
type BatchFunction ¶
BatchFunction is called with n keys after the keys passed to the loader reach the loader capacity
type Cache ¶
type Cache interface { // SetResult sets a single result for a specified key SetResult(context.Context, Key, Result) // SetResultMap passes a ResultMap to the cache SetResultMap(context.Context, ResultMap) // GetResult returns a single result for a key GetResult(context.Context, Key) (Result, bool) // GetResultMap returns a ResultMap for a set of keys. The returned ResultMap // only contains the values that belong to the provided keys GetResultMap(context.Context, ...Key) (ResultMap, bool) // Delete removes the specific value for the provided key Delete(context.Context, Key) bool // ClearAll cleans the cache ClearAll(context.Context) bool }
Cache provides an interface for caching strategies
func NewNoOpCache ¶
func NewNoOpCache() Cache
NewNoOpCache returns a cache strategy with no internal implementation
type DataLoader ¶
type DataLoader interface { // Load returns a Thunk for the specified Key. // Internally Load adds the provided key to the keys array and returns a callback // function which when called returns the value for the key Load(context.Context, Key) Thunk // LoadMany returns a ThunkMany for the specified keys. // Internally LoadMany adds the provided keys to the keys array and returns a callback // function which when called returns the values for the provided keys. LoadMany(context.Context, ...Key) ThunkMany }
DataLoader is the identifying interface for the dataloader. Each DataLoader instance tracks the resolved elements. Note that calling Load and LoadMany on the same dataloader instance will increment the same counter, once for each method call.
func NewDataLoader ¶
func NewDataLoader( capacity int, batch BatchFunction, fn StrategyFunction, opts ...Option, ) DataLoader
NewDataLoader returns a new DataLoader with a count capacity of `capacity`. The capacity value determines when the batch loader function will execute. The dataloader requires a strategy to execute and a cache strategy to use for storing data.
type Key ¶
type Key interface { // String should return a guaranteed unique string that can be used to identify // the element. It's purpose is to identify each record when storing the results. // Records which should be different but share the same key will be overwritten. String() string // Raw should return real value of the key. Raw() interface{} }
Key is an interface each element identifier must implement in order to be stored and cached in the ResultsMap
type Keys ¶
type Keys interface { Append(...Key) Capacity() int Length() int ClearAll() // Keys returns a an array of unique results after calling Raw on each key Keys() []interface{} IsEmpty() bool }
Keys wraps an array of keys and contains accessor methods
func NewKeysWith ¶
NewKeysWith is a helper method for returning a new keys array which includes the the provided keys
type LoadFinishFunc ¶ added in v0.4.0
type LoadFinishFunc func(Result)
LoadFinishFunc finishes the tracing for the Load function
type LoadManyFinishFunc ¶ added in v0.4.0
type LoadManyFinishFunc func(ResultMap)
LoadManyFinishFunc finishes the tracing for the LoadMany function
type Option ¶ added in v0.4.0
type Option func(*dataloader)
Option accepts the dataloader and sets an option on it.
func WithLogger ¶ added in v0.5.0
WithLogger adds a logger to the dataloader. The default is a no op logger
func WithTracer ¶ added in v0.4.0
WithTracer adds a tracer to the dataloader
type Result ¶
type Result struct { Result interface{} Err error }
Result is an alias for the resolved data by the batch loader
type ResultMap ¶
type ResultMap interface { Set(string, Result) GetValue(Key) (Result, bool) Length() int // Keys returns a slice of all unique identifiers used in the containing map (keys) Keys() []string GetValueForString(string) Result }
ResultMap maps each loaded elements Result against the elements unique identifier (Key)
func NewResultMap ¶
NewResultMap returns a new instance of the result map with the provided capacity. Each value defaults to nil
type Strategy ¶
type Strategy interface { // Load returns a Thunk for the specified Key. // Internally load adds the provided key to the keys array and returns a callback function linked // to the key which blocks when called until the the batch function is called. Load(context.Context, Key) Thunk // LoadMany returns a ThunkMany which returns a ResultMap for the keys it was called for. // When called, callback blocks until the batch function is called. LoadMany(context.Context, ...Key) ThunkMany // LoadNoNop doesn't block the caller and doesn't return a value when called. // LoadNoOp is called after a cache hit and the found result value is returned to the caller // and thus simply increments the loads call counter. LoadNoOp(context.Context) }
Strategy specifies the interface of loader strategies. A loader strategy specifies the process of calling the batch function and handling requests to fetch data.
type StrategyFunction ¶ added in v0.5.0
type StrategyFunction func(int, BatchFunction) Strategy
StrategyFunction defines the return type of strategy builder functions. A strategy builder function returns a specific strategy when called.
type Thunk ¶ added in v0.3.0
Thunk returns a result for the key that it was generated for. Calling the Thunk function will block until the result is returned from the batch function.
type ThunkMany ¶ added in v0.3.0
type ThunkMany func() ResultMap
ThunkMany returns a result map for the keys that it was generated for. Calling ThunkMany will block until the result is returned from the batch function.
type Tracer ¶ added in v0.4.0
type Tracer interface { // Load handles tracing for calls to the Load function Load(context.Context, Key) (context.Context, LoadFinishFunc) // LoadMany handles tracing for calls to the LoadMany function LoadMany(context.Context, []Key) (context.Context, LoadManyFinishFunc) // Batch handles tracing for calls to the BatchFunction function Batch(context.Context) (context.Context, BatchFinishFunc) }
Tracer is an interface that may be used to implement tracing.
func NewNoOpTracer ¶ added in v0.4.0
func NewNoOpTracer() Tracer
NewNoOpTracer returns an instance of a blank tracer with no action
func NewOpenTracingTracer ¶ added in v0.4.0
func NewOpenTracingTracer() Tracer
NewOpenTracingTracer returns an instance of a tracer conforming to the open tracing standard
Directories ¶
Path | Synopsis |
---|---|
once
Package once contains the implementation details for the once strategy.
|
Package once contains the implementation details for the once strategy. |
sozu
Package sozu contains implementation details for the sozu strategy.
|
Package sozu contains implementation details for the sozu strategy. |