Documentation ¶
Overview ¶
Package cache instruments patrickmn/go-cache interactions with Open Census
Example ¶
package main import ( "context" "fmt" "time" pcache "github.com/patrickmn/go-cache" cache "github.com/otternq/patrickmn-go-cache" ) func main() { var ( c = pcache.New(time.Minute, time.Minute) cacheWrapper = cache.Wrap(c, "default") found bool val interface{} ) cache.RegisterAllViews() cacheWrapper.Set(context.TODO(), "key", "value", time.Second) val, found = cacheWrapper.Get(context.TODO(), "key") fmt.Println("Found:", found) fmt.Println("Val:", val) }
Output: Found: true Val: value
Index ¶
- Variables
- func RegisterAllViews() error
- type Cacher
- type Wrapper
- func (w *Wrapper) Add(ctx context.Context, k string, x interface{}, d time.Duration) (err error)
- func (w *Wrapper) Decrement(ctx context.Context, k string, n int64) (err error)
- func (w *Wrapper) DecrementFloat(ctx context.Context, k string, n float64) (err error)
- func (w *Wrapper) DecrementFloat32(ctx context.Context, k string, n float32) (v float32, err error)
- func (w *Wrapper) DecrementFloat64(ctx context.Context, k string, n float64) (v float64, err error)
- func (w *Wrapper) DecrementInt(ctx context.Context, k string, n int) (v int, err error)
- func (w *Wrapper) DecrementInt16(ctx context.Context, k string, n int16) (v int16, err error)
- func (w *Wrapper) DecrementInt32(ctx context.Context, k string, n int32) (v int32, err error)
- func (w *Wrapper) DecrementInt64(ctx context.Context, k string, n int64) (v int64, err error)
- func (w *Wrapper) DecrementInt8(ctx context.Context, k string, n int8) (v int8, err error)
- func (w *Wrapper) DecrementUint(ctx context.Context, k string, n uint) (v uint, err error)
- func (w *Wrapper) DecrementUint16(ctx context.Context, k string, n uint16) (v uint16, err error)
- func (w *Wrapper) DecrementUint32(ctx context.Context, k string, n uint32) (v uint32, err error)
- func (w *Wrapper) DecrementUint64(ctx context.Context, k string, n uint64) (v uint64, err error)
- func (w *Wrapper) DecrementUint8(ctx context.Context, k string, n uint8) (v uint8, err error)
- func (w *Wrapper) DecrementUintptr(ctx context.Context, k string, n uintptr) (v uintptr, err error)
- func (w *Wrapper) Delete(ctx context.Context, k string)
- func (w *Wrapper) DeleteExpired(ctx context.Context)
- func (w *Wrapper) Flush(ctx context.Context)
- func (w *Wrapper) Get(ctx context.Context, k string) (v interface{}, found bool)
- func (w *Wrapper) GetWithExpiration(ctx context.Context, k string) (v interface{}, exp time.Time, found bool)
- func (w *Wrapper) Increment(ctx context.Context, k string, n int64) (err error)
- func (w *Wrapper) IncrementFloat(ctx context.Context, k string, n float64) (err error)
- func (w *Wrapper) IncrementFloat32(ctx context.Context, k string, n float32) (v float32, err error)
- func (w *Wrapper) IncrementFloat64(ctx context.Context, k string, n float64) (v float64, err error)
- func (w *Wrapper) IncrementInt(ctx context.Context, k string, n int) (v int, err error)
- func (w *Wrapper) IncrementInt16(ctx context.Context, k string, n int16) (v int16, err error)
- func (w *Wrapper) IncrementInt32(ctx context.Context, k string, n int32) (v int32, err error)
- func (w *Wrapper) IncrementInt64(ctx context.Context, k string, n int64) (v int64, err error)
- func (w *Wrapper) IncrementInt8(ctx context.Context, k string, n int8) (v int8, err error)
- func (w *Wrapper) IncrementUint(ctx context.Context, k string, n uint) (v uint, err error)
- func (w *Wrapper) IncrementUint16(ctx context.Context, k string, n uint16) (v uint16, err error)
- func (w *Wrapper) IncrementUint32(ctx context.Context, k string, n uint32) (v uint32, err error)
- func (w *Wrapper) IncrementUint64(ctx context.Context, k string, n uint64) (v uint64, err error)
- func (w *Wrapper) IncrementUint8(ctx context.Context, k string, n uint8) (v uint8, err error)
- func (w *Wrapper) IncrementUintptr(ctx context.Context, k string, n uintptr) (v uintptr, err error)
- func (w *Wrapper) ItemCount(ctx context.Context) (c int)
- func (w *Wrapper) Items(ctx context.Context) (items map[string]pgocache.Item)
- func (w *Wrapper) Load(ctx context.Context, r io.Reader) (err error)
- func (w *Wrapper) LoadFile(ctx context.Context, fname string) (err error)
- func (w *Wrapper) OnEvicted(ctx context.Context, f func(string, interface{}))
- func (w *Wrapper) Replace(ctx context.Context, k string, x interface{}, d time.Duration) (err error)
- func (w *Wrapper) Save(ctx context.Context, wr io.Writer) (err error)
- func (w *Wrapper) SaveFile(ctx context.Context, fname string) (err error)
- func (w *Wrapper) Set(ctx context.Context, k string, x interface{}, d time.Duration)
- func (w *Wrapper) SetDefault(ctx context.Context, k string, x interface{})
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
// GoCacheName is the name of the cache instance.
GoCacheName, _ = tag.NewKey("go_cache_name")
// GoCacheMethod is the cache method called.
GoCacheMethod, _ = tag.NewKey("go_cache_method")
// GoCacheStatus identifies found v.s not found.
GoCacheStatus, _ = tag.NewKey("go_cache_status")
DefaultTags = []tag.Key{GoCacheMethod, GoCacheStatus}
)
The following tags are aooplied to stats recorded by this package
View Source
var ( GoCacheLatencyView = &view.View{ Name: "go.cache/client/latency", Description: "The distribution of latency of various calls in milliseconds", Measure: MeasureLatencyMs, Aggregation: DefaultMillisecondsDistribution, TagKeys: DefaultTags, } GoCacheCallsView = &view.View{ Name: "go.cache/client/calls", Description: "The number of various calls of methods", Measure: MeasureLatencyMs, Aggregation: view.Count(), TagKeys: DefaultTags, } DefaultViews = []*view.View{GoCacheLatencyView, GoCacheCallsView} )
Package cache provides some convenience views. You still need to register these views for data to actually be collected. You can use the RegisterAllViews function for this.
View Source
var (
DefaultMillisecondsDistribution = view.Distribution(
0.0,
0.001,
0.005,
0.01,
0.05,
0.1,
0.5,
1.0,
1.5,
2.0,
2.5,
5.0,
10.0,
25.0,
50.0,
100.0,
200.0,
400.0,
600.0,
800.0,
1000.0,
1500.0,
2000.0,
2500.0,
5000.0,
10000.0,
20000.0,
40000.0,
100000.0,
200000.0,
500000.0,
)
)
Default distributions used by views in this package
View Source
var (
MeasureLatencyMs = stats.Int64("go.cache/latency", "The latency of calls in milliseconds", stats.UnitMilliseconds)
)
The following measures are supported for use in custom views.
Functions ¶
func RegisterAllViews ¶
func RegisterAllViews() error
RegisterAllViews registers all the cache views to enable collection of stats
Types ¶
type Cacher ¶
type Cacher interface { Add(c context.Context, k string, x interface{}, d time.Duration) error Decrement(c context.Context, k string, n int64) error DecrementFloat(c context.Context, k string, n float64) error DecrementFloat32(c context.Context, k string, n float32) (float32, error) DecrementFloat64(c context.Context, k string, n float64) (float64, error) DecrementInt(c context.Context, k string, n int) (int, error) DecrementInt16(c context.Context, k string, n int16) (int16, error) DecrementInt32(c context.Context, k string, n int32) (int32, error) DecrementInt64(c context.Context, k string, n int64) (int64, error) DecrementInt8(c context.Context, k string, n int8) (int8, error) DecrementUint(c context.Context, k string, n uint) (uint, error) DecrementUint16(c context.Context, k string, n uint16) (uint16, error) DecrementUint32(c context.Context, k string, n uint32) (uint32, error) DecrementUint64(c context.Context, k string, n uint64) (uint64, error) DecrementUint8(c context.Context, k string, n uint8) (uint8, error) DecrementUintptr(c context.Context, k string, n uintptr) (uintptr, error) Delete(c context.Context, k string) DeleteExpired(c context.Context) Flush(c context.Context) Get(c context.Context, k string) (interface{}, bool) GetWithExpiration(c context.Context, k string) (interface{}, time.Time, bool) Increment(c context.Context, k string, n int64) error IncrementFloat(c context.Context, k string, n float64) error IncrementFloat32(c context.Context, k string, n float32) (float32, error) IncrementFloat64(c context.Context, k string, n float64) (float64, error) IncrementInt(c context.Context, k string, n int) (int, error) IncrementInt16(c context.Context, k string, n int16) (int16, error) IncrementInt32(c context.Context, k string, n int32) (int32, error) IncrementInt64(c context.Context, k string, n int64) (int64, error) IncrementInt8(c context.Context, k string, n int8) (int8, error) IncrementUint(c context.Context, k string, n uint) (uint, error) IncrementUint16(c context.Context, k string, n uint16) (uint16, error) IncrementUint32(c context.Context, k string, n uint32) (uint32, error) IncrementUint64(c context.Context, k string, n uint64) (uint64, error) IncrementUint8(c context.Context, k string, n uint8) (uint8, error) IncrementUintptr(c context.Context, k string, n uintptr) (uintptr, error) ItemCount(c context.Context) int Items(c context.Context) map[string]pgocache.Item Load(c context.Context, r io.Reader) error LoadFile(c context.Context, fname string) error OnEvicted(c context.Context, f func(string, interface{})) Replace(c context.Context, k string, x interface{}, d time.Duration) error Save(c context.Context, w io.Writer) (err error) SaveFile(c context.Context, fname string) error Set(c context.Context, k string, x interface{}, d time.Duration) SetDefault(c context.Context, k string, x interface{}) }
Cacher defines a context aware implementation go-cache
type Wrapper ¶
func (*Wrapper) DecrementFloat ¶
func (*Wrapper) DecrementFloat32 ¶
func (*Wrapper) DecrementFloat64 ¶
func (*Wrapper) DecrementInt ¶
func (*Wrapper) DecrementInt16 ¶
func (*Wrapper) DecrementInt32 ¶
func (*Wrapper) DecrementInt64 ¶
func (*Wrapper) DecrementInt8 ¶
func (*Wrapper) DecrementUint ¶
func (*Wrapper) DecrementUint16 ¶
func (*Wrapper) DecrementUint32 ¶
func (*Wrapper) DecrementUint64 ¶
func (*Wrapper) DecrementUint8 ¶
func (*Wrapper) DecrementUintptr ¶
func (*Wrapper) DeleteExpired ¶
func (*Wrapper) GetWithExpiration ¶
func (*Wrapper) IncrementFloat ¶
func (*Wrapper) IncrementFloat32 ¶
func (*Wrapper) IncrementFloat64 ¶
func (*Wrapper) IncrementInt ¶
func (*Wrapper) IncrementInt16 ¶
func (*Wrapper) IncrementInt32 ¶
func (*Wrapper) IncrementInt64 ¶
func (*Wrapper) IncrementInt8 ¶
func (*Wrapper) IncrementUint ¶
func (*Wrapper) IncrementUint16 ¶
func (*Wrapper) IncrementUint32 ¶
func (*Wrapper) IncrementUint64 ¶
func (*Wrapper) IncrementUint8 ¶
func (*Wrapper) IncrementUintptr ¶
Click to show internal directories.
Click to hide internal directories.