cache

package
v2.1.56 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cache is a generated GoMock package.

Index

Constants

View Source
const (
	// For use with functions that take an expiration time.
	NoExpiration time.Duration = -1

	// For use with functions that take an expiration time. Equivalent to
	// passing in the same expiration duration as was given to New() or
	// NewFrom() when the cache was created (e.g. 5 minutes.)
	DefaultExpiration time.Duration = 0

	// For use with functions that do not clean up.
	NoCleanup time.Duration = -1
)
View Source
const (
	// CertifyCacheDirName is dir name of certify cache.
	CertifyCacheDirName = "certs"
)

Variables

This section is empty.

Functions

func NewCertifyMutliCache added in v2.0.6

func NewCertifyMutliCache(caches ...certify.Cache) certify.Cache

NewCertifyMutliCache returns a certify.Cache with multiple caches Such as, cache.NewCertifyMutliCache(certify.NewMemCache(), certify.DirCache("certs")) This multiple cache will get certs from mem cache first, then dir cache to avoid read from filesystem every times.

Types

type Cache

type Cache interface {
	Scan(m string, n int) ([]string, error)
	Set(k string, x any, d time.Duration)
	SetDefault(k string, x any)
	Add(k string, x any, d time.Duration) error
	Get(k string) (any, bool)
	GetWithExpiration(k string) (any, time.Time, bool)
	Delete(k string)
	DeleteExpired()
	Keys() []string
	OnEvicted(f func(string, any))
	Save(w io.Writer) (err error)
	SaveFile(fname string) error
	Load(r io.Reader) error
	LoadFile(fname string) error
	Items() map[string]Item
	ItemCount() int
	Flush()
}

func New

func New(defaultExpiration, cleanupInterval time.Duration) Cache

Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().

type Item

type Item struct {
	Object     any
	Expiration int64
}

func (Item) Expired

func (item Item) Expired() bool

Returns true if the item has expired.

type MockCache added in v2.1.28

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

MockCache is a mock of Cache interface.

func NewMockCache added in v2.1.28

func NewMockCache(ctrl *gomock.Controller) *MockCache

NewMockCache creates a new mock instance.

func (*MockCache) Add added in v2.1.28

func (m *MockCache) Add(k string, x any, d time.Duration) error

Add mocks base method.

func (*MockCache) Delete added in v2.1.28

func (m *MockCache) Delete(k string)

Delete mocks base method.

func (*MockCache) DeleteExpired added in v2.1.28

func (m *MockCache) DeleteExpired()

DeleteExpired mocks base method.

func (*MockCache) EXPECT added in v2.1.28

func (m *MockCache) EXPECT() *MockCacheMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCache) Flush added in v2.1.28

func (m *MockCache) Flush()

Flush mocks base method.

func (*MockCache) Get added in v2.1.28

func (m *MockCache) Get(k string) (any, bool)

Get mocks base method.

func (*MockCache) GetWithExpiration added in v2.1.28

func (m *MockCache) GetWithExpiration(k string) (any, time.Time, bool)

GetWithExpiration mocks base method.

func (*MockCache) ItemCount added in v2.1.28

func (m *MockCache) ItemCount() int

ItemCount mocks base method.

func (*MockCache) Items added in v2.1.28

func (m *MockCache) Items() map[string]Item

Items mocks base method.

func (*MockCache) Keys added in v2.1.28

func (m *MockCache) Keys() []string

Keys mocks base method.

func (*MockCache) Load added in v2.1.28

func (m *MockCache) Load(r io.Reader) error

Load mocks base method.

func (*MockCache) LoadFile added in v2.1.28

func (m *MockCache) LoadFile(fname string) error

LoadFile mocks base method.

func (*MockCache) OnEvicted added in v2.1.28

func (m *MockCache) OnEvicted(f func(string, any))

OnEvicted mocks base method.

func (*MockCache) Save added in v2.1.28

func (m *MockCache) Save(w io.Writer) error

Save mocks base method.

func (*MockCache) SaveFile added in v2.1.28

func (m *MockCache) SaveFile(fname string) error

SaveFile mocks base method.

func (*MockCache) Scan added in v2.1.32

func (m_2 *MockCache) Scan(m string, n int) ([]string, error)

Scan mocks base method.

func (*MockCache) Set added in v2.1.28

func (m *MockCache) Set(k string, x any, d time.Duration)

Set mocks base method.

func (*MockCache) SetDefault added in v2.1.28

func (m *MockCache) SetDefault(k string, x any)

SetDefault mocks base method.

type MockCacheMockRecorder added in v2.1.28

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

MockCacheMockRecorder is the mock recorder for MockCache.

func (*MockCacheMockRecorder) Add added in v2.1.28

func (mr *MockCacheMockRecorder) Add(k, x, d any) *gomock.Call

Add indicates an expected call of Add.

func (*MockCacheMockRecorder) Delete added in v2.1.28

func (mr *MockCacheMockRecorder) Delete(k any) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockCacheMockRecorder) DeleteExpired added in v2.1.28

func (mr *MockCacheMockRecorder) DeleteExpired() *gomock.Call

DeleteExpired indicates an expected call of DeleteExpired.

func (*MockCacheMockRecorder) Flush added in v2.1.28

func (mr *MockCacheMockRecorder) Flush() *gomock.Call

Flush indicates an expected call of Flush.

func (*MockCacheMockRecorder) Get added in v2.1.28

func (mr *MockCacheMockRecorder) Get(k any) *gomock.Call

Get indicates an expected call of Get.

func (*MockCacheMockRecorder) GetWithExpiration added in v2.1.28

func (mr *MockCacheMockRecorder) GetWithExpiration(k any) *gomock.Call

GetWithExpiration indicates an expected call of GetWithExpiration.

func (*MockCacheMockRecorder) ItemCount added in v2.1.28

func (mr *MockCacheMockRecorder) ItemCount() *gomock.Call

ItemCount indicates an expected call of ItemCount.

func (*MockCacheMockRecorder) Items added in v2.1.28

func (mr *MockCacheMockRecorder) Items() *gomock.Call

Items indicates an expected call of Items.

func (*MockCacheMockRecorder) Keys added in v2.1.28

func (mr *MockCacheMockRecorder) Keys() *gomock.Call

Keys indicates an expected call of Keys.

func (*MockCacheMockRecorder) Load added in v2.1.28

func (mr *MockCacheMockRecorder) Load(r any) *gomock.Call

Load indicates an expected call of Load.

func (*MockCacheMockRecorder) LoadFile added in v2.1.28

func (mr *MockCacheMockRecorder) LoadFile(fname any) *gomock.Call

LoadFile indicates an expected call of LoadFile.

func (*MockCacheMockRecorder) OnEvicted added in v2.1.28

func (mr *MockCacheMockRecorder) OnEvicted(f any) *gomock.Call

OnEvicted indicates an expected call of OnEvicted.

func (*MockCacheMockRecorder) Save added in v2.1.28

func (mr *MockCacheMockRecorder) Save(w any) *gomock.Call

Save indicates an expected call of Save.

func (*MockCacheMockRecorder) SaveFile added in v2.1.28

func (mr *MockCacheMockRecorder) SaveFile(fname any) *gomock.Call

SaveFile indicates an expected call of SaveFile.

func (*MockCacheMockRecorder) Scan added in v2.1.32

func (mr *MockCacheMockRecorder) Scan(m, n any) *gomock.Call

Scan indicates an expected call of Scan.

func (*MockCacheMockRecorder) Set added in v2.1.28

func (mr *MockCacheMockRecorder) Set(k, x, d any) *gomock.Call

Set indicates an expected call of Set.

func (*MockCacheMockRecorder) SetDefault added in v2.1.28

func (mr *MockCacheMockRecorder) SetDefault(k, x any) *gomock.Call

SetDefault indicates an expected call of SetDefault.

Jump to

Keyboard shortcuts

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