pcache

package
v1.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTxDuration = 60 * time.Second
)

Variables

This section is empty.

Functions

func ValueToInt32

func ValueToInt32(v Value) int32

func ValueToString

func ValueToString(v Value) string

Types

type Cache

type Cache struct {
	Loader                  LoaderFunc
	DiskCache               *DiskCache // we do not cache errors on disk
	DiskCacheNamespace      string
	MaxMemCacheSize         int
	SpreadCacheTTL          bool
	DefaultCacheTTL         time.Duration
	DefaultNegativeCacheTTL time.Duration
	LoadMinInterval         time.Duration
	LoadBurst               int
	Empty                   func() Value
	// contains filtered or unexported fields
}

func (*Cache) Close

func (c *Cache) Close()

func (*Cache) DiskCacheSize

func (c *Cache) DiskCacheSize() int

func (*Cache) GetCached

func (c *Cache) GetCached(now time.Time, key []byte) Result

func (*Cache) GetCachedString

func (c *Cache) GetCachedString(now time.Time, key string) Result

func (*Cache) GetOrLoad

func (c *Cache) GetOrLoad(now time.Time, key string, extra interface{}) Result

Never returns empty result

func (*Cache) GetOrLoadCallback

func (c *Cache) GetOrLoadCallback(now time.Time, key string, extra interface{}, cb Callback) Result

If empty result is returned, cb will be called in future

func (*Cache) SetBootstrapValue

func (c *Cache) SetBootstrapValue(now time.Time, key string, v Value, ttl time.Duration) error

type Callback

type Callback func(r Result)

type DiskCache

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

func OpenDiskCache

func OpenDiskCache(cacheFilename string, txDuration time.Duration) (*DiskCache, error)

func (*DiskCache) Close

func (dc *DiskCache) Close() error

func (*DiskCache) Count

func (dc *DiskCache) Count(ns string) (int, error)

func (*DiskCache) Erase

func (dc *DiskCache) Erase(ns string, key string) error

erasing not existing is nop

func (*DiskCache) EraseNamespace

func (dc *DiskCache) EraseNamespace(ns string) error

erasing not existing is nop

func (*DiskCache) Get

func (dc *DiskCache) Get(ns string, key string) ([]byte, time.Time, time.Duration, error, bool)

func (*DiskCache) List

func (dc *DiskCache) List(ns string) ([]ListResult, error)

func (*DiskCache) Set

func (dc *DiskCache) Set(ns string, key string, val []byte, update time.Time, ttl time.Duration) error

type Int32Value

type Int32Value int32

func (Int32Value) MarshalBinary

func (i Int32Value) MarshalBinary() ([]byte, error)

func (*Int32Value) UnmarshalBinary

func (i *Int32Value) UnmarshalBinary(data []byte) error

type ListResult

type ListResult struct {
	Value  []byte        `db:"value"`
	Update time.Time     `db:"update_time"`
	TTL    time.Duration `db:"ttl"`
}

type LoaderFunc

type LoaderFunc func(ctx context.Context, key string, extra interface{}) (Value, time.Duration, error)

type Result

type Result struct {
	Value Value
	Err   error
	TTL   time.Duration
}

func (Result) Found

func (e Result) Found() bool

type StringValue

type StringValue string

func (StringValue) MarshalBinary

func (s StringValue) MarshalBinary() ([]byte, error)

func (*StringValue) UnmarshalBinary

func (s *StringValue) UnmarshalBinary(data []byte) error

type Value

func Int32ToValue

func Int32ToValue(i int32) Value

func StringToValue

func StringToValue(s string) Value

Jump to

Keyboard shortcuts

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