Documentation ¶
Overview ¶
Package agdcache contains cache interfaces, helpers, and implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clearer ¶
type Clearer interface {
// Clear completely clears cache.
Clear()
}
Clearer is a partial cache interface.
type DefaultManager ¶
type DefaultManager struct {
// contains filtered or unexported fields
}
DefaultManager implements the Manager interface that stores caches and can clear them by id
func NewDefaultManager ¶
func NewDefaultManager() (m *DefaultManager)
NewDefaultManager returns a new initialized *DefaultManager.
func (*DefaultManager) Add ¶
func (m *DefaultManager) Add(id string, cache Clearer)
Add implements the Manager interface for *DefaultManager. Note that it replaces the saved cache with the same id if there is one.
func (*DefaultManager) ClearByID ¶
func (m *DefaultManager) ClearByID(id string)
ClearByID implements the Manager interface for *DefaultManager.
func (*DefaultManager) IDs ¶
func (m *DefaultManager) IDs() (ids []string)
IDs returns a sorted list of stored cache identifiers.
type Empty ¶
type Empty[K, T any] struct{}
Empty is an Interface implementation that does nothing.
func (Empty[K, T]) Clear ¶
func (c Empty[K, T]) Clear()
Clear implements the Interface interface for Empty.
func (Empty[K, T]) Len ¶
Len implements the Interface interface for Empty. n may include items that have expired, but have not yet been cleaned up.
type EmptyManager ¶
type EmptyManager struct{}
EmptyManager implements the Manager interface that does nothing.
func (EmptyManager) Add ¶
func (EmptyManager) Add(_ string, _ Clearer)
Add implements the Manager interface for *EmptyManager.
func (EmptyManager) ClearByID ¶
func (EmptyManager) ClearByID(_ string)
ClearByID implements the Manager interface for *EmptyManager.
type Interface ¶
type Interface[K, T any] interface { // Set sets key and val as cache pair. Set(key K, val T) // SetWithExpire sets key and val as cache pair with expiration time. SetWithExpire(key K, val T, expiration time.Duration) // Get gets val from the cache using key. Get(key K) (val T, ok bool) // Clearer completely clears cache. Clearer // Len returns the number of items in the cache. Len() (n int) }
Interface is the cache interface.
type LRU ¶
type LRU[K, T any] struct { // contains filtered or unexported fields }
LRU is an Interface implementation.
func (*LRU[K, T]) Clear ¶
func (c *LRU[K, T]) Clear()
Clear implements the Interface interface for *LRU.
func (*LRU[K, T]) Len ¶
Len implements the Interface interface for *LRU. n may include items that have expired, but have not yet been cleaned up.
type LRUConfig ¶
type LRUConfig struct { // Count is the maximum number of elements to keep in the cache. It must be // positive. // // TODO(a.garipov): Make uint64. Count int }
LRUConfig is a configuration structure of a cache.
type Manager ¶
type Manager interface { // Add adds cache by id. cache must not be nil. // // TODO(s.chzhen): Add Set method that rewrites the cache associated with // id (current Add implementation). // // TODO(s.chzhen): Add panic on adding cache with duplicate id. Add(id string, cache Clearer) // ClearByID clears cache by id. ClearByID(id string) }
Manager is the cache manager interface. All methods must be safe for concurrent use.