pine

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 6 Imported by: 0

README

pine

pine is a runtime cache tool

Install

go get github.com/johnhaha/pine@v0.0.9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cache *bigcache.BigCache

Functions

func InitCache added in v0.0.8

func InitCache(ctx context.Context, eviction time.Duration) error

normally 10*time.Minute for eviction

func Remove added in v0.0.7

func Remove(id string)

remove cache with id

Types

type CacheData added in v0.0.3

type CacheData[T any] struct {
	Data      T
	FromCache bool
}

func Get added in v0.0.3

func Get[T any](id string, withCache bool, execution func() (T, error)) (*CacheData[T], error)

get from cache if exists, store cache with execution if not exists

func SingleRun added in v0.0.9

func SingleRun[T any](key string, execution func() (T, error)) (*CacheData[T], error)

func (*CacheData[T]) Decode added in v0.0.8

func (data *CacheData[T]) Decode(cache []byte) error

func (*CacheData[T]) Encode added in v0.0.8

func (data *CacheData[T]) Encode() ([]byte, error)

type CacheLife

type CacheLife struct {
	Lifetime  int64
	UpdatedAt int64
}

func (*CacheLife) Expired

func (life *CacheLife) Expired() bool

func (*CacheLife) Update

func (life *CacheLife) Update()

type CachedData

type CachedData[T any] struct {
	Data *T
	CacheLife
}

func NewCachedData

func NewCachedData[T any](lifeTime int64) *CachedData[T]

func (*CachedData[T]) Clear added in v0.0.3

func (data *CachedData[T]) Clear()

func (*CachedData[T]) Get added in v0.0.3

func (data *CachedData[T]) Get(onExpire func() (*T, error)) (*T, error)

func (*CachedData[T]) Set added in v0.0.3

func (data *CachedData[T]) Set(d *T)

type CachedList

type CachedList[T any] struct {
	Data [][]T
	CacheLife
	Capacity int
	sync.RWMutex
}

func NewCachedList

func NewCachedList[T any](lifeTime int64, capacity int) *CachedList[T]

func (*CachedList[T]) Append added in v0.0.3

func (list *CachedList[T]) Append(data []T, at int)

func (*CachedList[T]) Clear added in v0.0.3

func (list *CachedList[T]) Clear()

clear cached list

func (*CachedList[T]) Count added in v0.0.3

func (list *CachedList[T]) Count() (page int, num int)

return last element of cached list

func (*CachedList[T]) First added in v0.0.3

func (list *CachedList[T]) First() []T

return first element of cached list

func (*CachedList[T]) GetPage added in v0.0.3

func (list *CachedList[T]) GetPage(page int, getData func(page int) ([]T, error)) (listData []T, err error)

get list from specific index

func (*CachedList[T]) Last added in v0.0.3

func (list *CachedList[T]) Last() []T

return last element of cached list

func (*CachedList[T]) Length added in v0.0.3

func (list *CachedList[T]) Length() int

get length of cached list

type ExpireError

type ExpireError struct {
}

func NewExpireError

func NewExpireError() *ExpireError

func (*ExpireError) Error

func (e *ExpireError) Error() string

type ListElement

type ListElement interface {
	GetUID() string
}

type PageOutOfRangeError

type PageOutOfRangeError struct {
}

func NewPageOutOfRangeError

func NewPageOutOfRangeError() *PageOutOfRangeError

func (*PageOutOfRangeError) Error

func (e *PageOutOfRangeError) Error() string

Jump to

Keyboard shortcuts

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