caches

package module
v0.0.0-...-a114629 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: BSD-3-Clause Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Global = New(logger.DefaultManager.New("caches", "global"))
View Source
var Persistent string = ""

Functions

func Join

func Join(names ...string) string

Join multiple cache name together

Types

type Creator

type Creator func() (interface{}, error)

type Data

type Data struct {
	Key   string `json:"-"`
	Data  interface{}
	Error error `json:",omitempty"`
	// contains filtered or unexported fields
}

func NewData

func NewData(key string, updater Updater, expireAt time.Duration) *Data

func NilData

func NilData(key string) *Data

func SData

func SData(key string, data interface{}) *Data

SData is constants data

func (*Data) CreateAt

func (d *Data) CreateAt() time.Time

func (*Data) ExpireAt

func (d *Data) ExpireAt() *time.Time

func (*Data) Extend

func (d *Data) Extend() *Data

Extend will update updateAt to now()

func (*Data) Fetch

func (d *Data) Fetch() (bool, error)

Fetch will update only if data is missing or expired return true if data got updated

func (*Data) FetchData

func (d *Data) FetchData() (interface{}, error)

FetchData same with Fetch but return data out

func (*Data) Get

func (d *Data) Get() (interface{}, error)

func (*Data) IsExist

func (d *Data) IsExist() bool

func (*Data) IsExpired

func (d *Data) IsExpired() bool

func (*Data) String

func (d *Data) String() string

func (*Data) Update

func (d *Data) Update() error

Update will force call updater and update updateAt value

func (*Data) UpdateAt

func (d *Data) UpdateAt() time.Time

func (*Data) UpdateData

func (d *Data) UpdateData() (interface{}, error)

UpdateData same with Update but return data out

type Service

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

func New

func New(l *logger.Logger) *Service

func (*Service) Bucket

func (s *Service) Bucket(key string, value interface{}, limit int, expireAt string) error

Bucket will keep value as []interface{}

func (*Service) Fetch

func (s *Service) Fetch(key string, updater Updater, expireAt string) (bool, error)

func (*Service) FetchAll

func (s *Service) FetchAll() error

func (*Service) Get

func (s *Service) Get(key string) *Data

func (*Service) Has

func (s *Service) Has(key string) bool

func (*Service) Increase

func (s *Service) Increase(key string)

Increase is shorted method for increase number everytime it's called by 1

func (*Service) IncreaseN

func (s *Service) IncreaseN(key string, increase int)

Increase is shorted method for increase number everytime it's called by n

func (*Service) Set

func (s *Service) Set(key string, value interface{}, expireAt string) error

func (*Service) SetData

func (s *Service) SetData(data *Data) error

func (*Service) SetFn

func (s *Service) SetFn(key string, creator Creator, expireAt string) error

func (*Service) Size

func (s *Service) Size() int

func (*Service) String

func (s *Service) String() string

func (*Service) Update

func (s *Service) Update(key string, value interface{}, expireAt string)

func (*Service) UpdateFn

func (s *Service) UpdateFn(key string, updater Updater, expireAt string) error

type Updater

type Updater func(o interface{}) (interface{}, error)

Jump to

Keyboard shortcuts

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