Documentation
¶
Overview ¶
Package events holds every event a cache Repository fires.
A listener written against events.CacheHit reads e.Key, e.Value and e.StoreName; the other events carry the fields their names imply, and CacheEvent carries the ones they all share.
They are values, not an interface. Nothing here dispatches: cache.Dispatcher is the one method the Repository needs, and what is on the other side of it is the application's business.
Index ¶
- type CacheEvent
- type CacheFailedOver
- type CacheFlushFailed
- type CacheFlushed
- type CacheFlushing
- type CacheHit
- type CacheLocksFlushFailed
- type CacheLocksFlushed
- type CacheLocksFlushing
- type CacheMissed
- type ForgettingKey
- type KeyForgetFailed
- type KeyForgotten
- type KeyWriteFailed
- type KeyWritten
- type RetrievingKey
- type RetrievingManyKeys
- type WritingKey
- type WritingManyKeys
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheEvent ¶
type CacheEvent struct {
// StoreName is the name of the cache store the event came from. It is empty
// when the repository was built without one.
StoreName string
// Key is the key the event is about.
Key string
// Tags are the tags assigned to the key, and nil on an untagged repository.
Tags []string
}
CacheEvent is what every keyed cache event carries: which store, which key, and under which tags.
It is a struct the other events embed, so a listener written against CacheHit reads e.Key and e.StoreName directly.
It is not an interface. A listener that wants "any cache event" switches on the concrete type, and a listener that wants the common part reads the embedded CacheEvent.
func (*CacheEvent) SetTags ¶
func (e *CacheEvent) SetTags(tags []string) *CacheEvent
SetTags sets the tags for the cache event.
It is on a pointer receiver and returns the event, so assigning tags and dispatching read as one line.
type CacheFailedOver ¶
type CacheFailedOver struct {
// StoreName is the name of the cache store that failed.
StoreName string
// Err is what it failed with.
Err error
}
CacheFailedOver is fired when one store of a failover set refused an operation and the next one was tried.
It fires once per store per failure, and only when that store was not already failing -- so a cache that has been down for an hour produces one event, not one per request.
func NewCacheFailedOver ¶
func NewCacheFailedOver(storeName string, err error) *CacheFailedOver
NewCacheFailedOver returns the event.
type CacheFlushFailed ¶
type CacheFlushFailed struct {
// StoreName is the name of the cache store.
StoreName string
// Tags are the tags that were being flushed.
Tags []string
}
CacheFlushFailed is fired when a flush did not happen.
func NewCacheFlushFailed ¶
func NewCacheFlushFailed(storeName string, tags []string) *CacheFlushFailed
NewCacheFlushFailed returns the event.
func (*CacheFlushFailed) SetTags ¶
func (e *CacheFlushFailed) SetTags(tags []string) *CacheFlushFailed
SetTags sets the tags for the event and returns it.
type CacheFlushed ¶
type CacheFlushed struct {
// StoreName is the name of the cache store.
StoreName string
// Tags are the tags that were flushed.
Tags []string
}
CacheFlushed is fired after a store was flushed.
func NewCacheFlushed ¶
func NewCacheFlushed(storeName string, tags []string) *CacheFlushed
NewCacheFlushed returns the event.
func (*CacheFlushed) SetTags ¶
func (e *CacheFlushed) SetTags(tags []string) *CacheFlushed
SetTags sets the tags for the event and returns it.
type CacheFlushing ¶
type CacheFlushing struct {
// StoreName is the name of the cache store.
StoreName string
// Tags are the tags being flushed, and nil when the whole namespace is.
Tags []string
}
CacheFlushing is fired before a store is flushed.
It carries no key, because a flush is about all of them.
func NewCacheFlushing ¶
func NewCacheFlushing(storeName string, tags []string) *CacheFlushing
NewCacheFlushing returns the event.
func (*CacheFlushing) SetTags ¶
func (e *CacheFlushing) SetTags(tags []string) *CacheFlushing
SetTags sets the tags for the event and returns it.
type CacheHit ¶
type CacheHit struct {
CacheEvent
// Value is the value that was retrieved.
Value any
}
CacheHit is fired when a key was found.
type CacheLocksFlushFailed ¶
type CacheLocksFlushFailed struct {
// StoreName is the name of the cache store.
StoreName string
}
CacheLocksFlushFailed is fired when the locks could not be released.
func NewCacheLocksFlushFailed ¶
func NewCacheLocksFlushFailed(storeName string) *CacheLocksFlushFailed
NewCacheLocksFlushFailed returns the event.
type CacheLocksFlushed ¶
type CacheLocksFlushed struct {
// StoreName is the name of the cache store.
StoreName string
}
CacheLocksFlushed is fired after every lock in a store was released.
func NewCacheLocksFlushed ¶
func NewCacheLocksFlushed(storeName string) *CacheLocksFlushed
NewCacheLocksFlushed returns the event.
type CacheLocksFlushing ¶
type CacheLocksFlushing struct {
// StoreName is the name of the cache store.
StoreName string
}
CacheLocksFlushing is fired before every lock in a store is released.
func NewCacheLocksFlushing ¶
func NewCacheLocksFlushing(storeName string) *CacheLocksFlushing
NewCacheLocksFlushing returns the event.
type CacheMissed ¶
type CacheMissed struct{ CacheEvent }
CacheMissed is fired when a key was not found.
It is the event a cache hit rate is computed from, together with CacheHit.
func NewCacheMissed ¶
func NewCacheMissed(storeName, key string, tags []string) *CacheMissed
NewCacheMissed returns the event.
type ForgettingKey ¶
type ForgettingKey struct{ CacheEvent }
ForgettingKey is fired before a key is removed. KeyForgotten or KeyForgetFailed follows it.
func NewForgettingKey ¶
func NewForgettingKey(storeName, key string, tags []string) *ForgettingKey
NewForgettingKey returns the event.
type KeyForgetFailed ¶
type KeyForgetFailed struct{ CacheEvent }
KeyForgetFailed is fired when a key could not be removed.
It is the one that matters after a deploy: an invalidation that failed leaves the old value being served, and nothing else says so.
func NewKeyForgetFailed ¶
func NewKeyForgetFailed(storeName, key string, tags []string) *KeyForgetFailed
NewKeyForgetFailed returns the event.
type KeyForgotten ¶
type KeyForgotten struct{ CacheEvent }
KeyForgotten is fired after a key was removed.
func NewKeyForgotten ¶
func NewKeyForgotten(storeName, key string, tags []string) *KeyForgotten
NewKeyForgotten returns the event.
type KeyWriteFailed ¶
type KeyWriteFailed struct {
CacheEvent
// Value is the value that would have been written.
Value any
// Seconds is how long the key should have been valid for.
Seconds int
}
KeyWriteFailed is fired when a write did not happen.
This is the event worth listening to: a cache that has quietly stopped accepting writes looks exactly like a cache with a very low hit rate, and only this tells the two apart.
func NewKeyWriteFailed ¶
func NewKeyWriteFailed(storeName, key string, value any, seconds int, tags []string) *KeyWriteFailed
NewKeyWriteFailed returns the event.
type KeyWritten ¶
type KeyWritten struct {
CacheEvent
// Value is the value that was written.
Value any
// Seconds is how long the key is valid for.
Seconds int
}
KeyWritten is fired after a key was written.
func NewKeyWritten ¶
func NewKeyWritten(storeName, key string, value any, seconds int, tags []string) *KeyWritten
NewKeyWritten returns the event.
type RetrievingKey ¶
type RetrievingKey struct{ CacheEvent }
RetrievingKey is fired before a key is read.
It is the "about to look" event, and it fires whether or not anything is there -- CacheHit or CacheMissed follows it.
func NewRetrievingKey ¶
func NewRetrievingKey(storeName, key string, tags []string) *RetrievingKey
NewRetrievingKey returns the event.
type RetrievingManyKeys ¶
type RetrievingManyKeys struct {
CacheEvent
// Keys are the keys being retrieved.
Keys []string
}
RetrievingManyKeys is fired before several keys are read at once.
func NewRetrievingManyKeys ¶
func NewRetrievingManyKeys(storeName string, keys []string, tags []string) *RetrievingManyKeys
NewRetrievingManyKeys returns the event.
Key is the first of keys, and the empty string when there are none.
type WritingKey ¶
type WritingKey struct {
CacheEvent
// Value is the value that will be written.
Value any
// Seconds is how long the key should be valid for. It is a whole number of
// seconds rather than a time.Duration, so a listener that formats or logs
// it does not have to convert.
Seconds int
}
WritingKey is fired before a key is written. KeyWritten or KeyWriteFailed follows it.
func NewWritingKey ¶
func NewWritingKey(storeName, key string, value any, seconds int, tags []string) *WritingKey
NewWritingKey returns the event.
type WritingManyKeys ¶
type WritingManyKeys struct {
CacheEvent
// Keys are the keys being written.
Keys []string
// Values are the values being written, in the order of Keys.
Values []any
// Seconds is how long the keys should be valid for.
Seconds int
}
WritingManyKeys is fired before several keys are written at once.
func NewWritingManyKeys ¶
func NewWritingManyKeys(storeName string, keys []string, values []any, seconds int, tags []string) *WritingManyKeys
NewWritingManyKeys returns the event.
Key is the first of keys, and the empty string when there are none.