Documentation ¶
Overview ¶
Package memorycachex implements the cachex.Cache interface as a in-memory cache store. It uses Mockingjay as the cache replacement policy.
Index ¶
- Constants
- type Entry
- type MemoryCache
- func (mc *MemoryCache) Delete(_ context.Context, key string) error
- func (mc *MemoryCache) Get(_ context.Context, key string) (*http.Response, error)
- func (mc *MemoryCache) Policy() *pagecache.Policy
- func (mc *MemoryCache) Purge(_ context.Context) error
- func (mc *MemoryCache) Set(_ context.Context, key string, response *http.Response, ...) error
Constants ¶
View Source
const ( ErrKeyEmpty xerrors.Error = "key must not be empty" ErrKeyMismatch xerrors.Error = "key mismatch" ErrValueEmpty xerrors.Error = "value must not be empty" ErrExpirationZero xerrors.Error = "expiration must not be zero" ErrMarshalResponse xerrors.Error = "failed to marshal response" ErrUnmarshalResponse xerrors.Error = "failed to unmarshal response" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct { Key string Expiration time.Time Request []byte Response []byte Size uint64 Frequency uint64 }
Entry represents a single cache entry. Entry is not tread-safe and should be protected by a sync.Mutex.
func NewEntry ¶
NewEntry creates a new cache entry with the specified key and expiration. You should call SerializeResponse after creating the entry to store the response.
func (*Entry) Access ¶
func (e *Entry) Access()
Access increments the frequency counter when the entry is accessed.
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is an in-memory cache implementing the Cache interface.
func NewCache ¶
func NewCache(policy *pagecache.Policy, capacity uint64) *MemoryCache
NewCache creates a new MemoryCache instance with the specified policy and capacity.
func (*MemoryCache) Policy ¶
func (mc *MemoryCache) Policy() *pagecache.Policy
Click to show internal directories.
Click to hide internal directories.