cache

package module
v0.0.0-...-2151a63 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2018 License: Apache-2.0 Imports: 5 Imported by: 3

README

cache GoDoc

Cache library for APIBox.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a synchronised map of items that auto-expire once stale

func NewCache

func NewCache(expire time.Duration) *Cache

NewCache is a helper to create instance of the Cache struct

func NewCacheEx

func NewCacheEx(expire, cleanupInterval time.Duration) *Cache

NewCacheEx is a helper to create instance of the Cache struct with specified cleanup interval

func (*Cache) Count

func (cache *Cache) Count() int

Count returns the number of items in the cache (helpful for tracking memory leaks)

func (*Cache) Get

func (cache *Cache) Get(key string) (item *Item, found bool)

Get is a thread-safe way to lookup items Every lookup, also touches the item, hence extending it's life

func (*Cache) Has

func (cache *Cache) Has(key string) (found bool)

Has is a thread-safe way to check if item exists.

func (*Cache) Set

func (cache *Cache) Set(key string, data interface{})

Set is a thread-safe way to add new items to the map

func (*Cache) SetIfNotExist

func (cache *Cache) SetIfNotExist(key string, data interface{}) (ok bool)

SetIfNotExist is a thread-safe way to add new items to the map. Add successfully only when item is not exists.

type Item

type Item struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Item represents a record in the cache map

func (*Item) Array

func (i *Item) Array() ([]interface{}, error)

Array type asserts to an `array`

func (*Item) Bool

func (i *Item) Bool() (bool, error)

Bool type asserts to `bool`

func (*Item) Bytes

func (i *Item) Bytes() ([]byte, error)

Bytes type asserts to `[]byte`

func (*Item) Float64

func (i *Item) Float64() (float64, error)

Float64 coerces into a float64

func (*Item) Int

func (i *Item) Int() (int, error)

Int coerces into an int

func (*Item) Int64

func (i *Item) Int64() (int64, error)

Int64 coerces into an int64

func (*Item) Map

func (i *Item) Map() (map[string]interface{}, error)

Map type asserts to `map`

func (*Item) MustArray

func (i *Item) MustArray(args ...[]interface{}) []interface{}

MustArray guarantees the return of a `[]interface{}` (with optional default)

useful when you want to interate over array values in a succinct manner:

for i, v := range js.Get("results").MustArray() {
	fmt.Println(i, v)
}

func (*Item) MustBool

func (i *Item) MustBool(args ...bool) bool

MustBool guarantees the return of a `bool` (with optional default)

useful when you explicitly want a `bool` in a single value return context:

myFunc(js.Get("param1").MustBool(), js.Get("optional_param").MustBool(true))

func (*Item) MustFloat64

func (i *Item) MustFloat64(args ...float64) float64

MustFloat64 guarantees the return of a `float64` (with optional default)

useful when you explicitly want a `float64` in a single value return context:

myFunc(js.Get("param1").MustFloat64(), js.Get("optional_param").MustFloat64(5.150))

func (*Item) MustInt

func (i *Item) MustInt(args ...int) int

MustInt guarantees the return of an `int` (with optional default)

useful when you explicitly want an `int` in a single value return context:

myFunc(js.Get("param1").MustInt(), js.Get("optional_param").MustInt(5150))

func (*Item) MustInt64

func (i *Item) MustInt64(args ...int64) int64

MustInt64 guarantees the return of an `int64` (with optional default)

useful when you explicitly want an `int64` in a single value return context:

myFunc(js.Get("param1").MustInt64(), js.Get("optional_param").MustInt64(5150))

func (*Item) MustMap

func (i *Item) MustMap(args ...map[string]interface{}) map[string]interface{}

MustMap guarantees the return of a `map[string]interface{}` (with optional default)

useful when you want to interate over map values in a succinct manner:

for k, v := range js.Get("dictionary").MustMap() {
	fmt.Println(k, v)
}

func (*Item) MustString

func (i *Item) MustString(args ...string) string

MustString guarantees the return of a `string` (with optional default)

useful when you explicitly want a `string` in a single value return context:

myFunc(js.Get("param1").MustString(), js.Get("optional_param").MustString("my_default"))

func (*Item) MustUint64

func (i *Item) MustUint64(args ...uint64) uint64

MustUInt64 guarantees the return of an `uint64` (with optional default)

useful when you explicitly want an `uint64` in a single value return context:

myFunc(js.Get("param1").MustUint64(), js.Get("optional_param").MustUint64(5150))

func (*Item) String

func (i *Item) String() (string, error)

String type asserts to `string`

func (*Item) StringArray

func (i *Item) StringArray() ([]string, error)

StringArray type asserts to an `array` of `string`

func (*Item) Uint64

func (i *Item) Uint64() (uint64, error)

Uint64 coerces into an uint64

Jump to

Keyboard shortcuts

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