cache

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Read(string) interface{}
	Write(string, interface{}, time.Duration) error
	Delete(string)
	Clear()
}

Cache is an interface for caches

type CacheWrapper

type CacheWrapper struct {
	Data              interface{}
	ExpiresAtUnixNano int64
}

type GoCache

type GoCache struct {
	cache.Cache
}

Implements our Cache interface

func NewGoCache

func NewGoCache(defaultExpiration, cleanupInterval time.Duration) *GoCache

NewGoCache creates a new GoCache.

func (*GoCache) Clear

func (c *GoCache) Clear()

func (*GoCache) Read

func (c *GoCache) Read(key string) interface{}

func (*GoCache) Write

func (c *GoCache) Write(key string, item interface{}, exp time.Duration) error

For oauth2, exp being 0 means no expiration

type SandCache

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

SandCache contains a primary and an optional secondary cache. The primary cache is an in-memory cache. If the secondary cache is nil, the primary will still be used. The main purpose for the secondary cache is to use a central cache (like a TLS-enabled Redis) shared by multiple processes/servers of the same app, so that they can coordinate on the cached data.

func NewSandCache

func NewSandCache(defaultExpTime time.Duration, secondary Cache) *SandCache

NewSandCache creates a primary cache with the defaultExpTime as default expiration time. The secondary cache should be a central cache shared by multiple processes or servers.

func (*SandCache) Delete

func (sc *SandCache) Delete(key string)

For unit tests

func (*SandCache) DirectWrite

func (sc *SandCache) DirectWrite(key string, value interface{}, exp time.Duration)

func (*SandCache) Read

func (sc *SandCache) Read(key string, marginSec float64) interface{}

func (*SandCache) ReadRaw

func (sc *SandCache) ReadRaw(key string, marginSec float64) *CacheWrapper

func (*SandCache) ReadSecondaryRaw

func (sc *SandCache) ReadSecondaryRaw(key string, marginSec float64) (wrapper *CacheWrapper)

func (*SandCache) Write

func (sc *SandCache) Write(key string, value interface{}, exp time.Duration) (data interface{}, err error)

Jump to

Keyboard shortcuts

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