Documentation ¶
Index ¶
- Variables
- func NewOverwriteError(existing *CacheResult) error
- type AsyncWriter
- type CacheDriver
- type CacheProvider
- type CacheReader
- type CacheResult
- type MemCacheAsyncWriter
- type MemCacheProvider
- func (m *MemCacheProvider) BulkWriter(ctx context.Context, opts ...WriterOption) (AsyncWriter, error)
- func (m *MemCacheProvider) Close(ctx context.Context) error
- func (m *MemCacheProvider) Get(ctx context.Context, key cachekey.CacheKey) *CacheResult
- func (m *MemCacheProvider) HealthCheck(ctx context.Context) (bool, error)
- func (mp *MemCacheProvider) Name() string
- func (m *MemCacheProvider) Prepare(ctx context.Context) error
- type OverwriteError
- type WriterOption
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoEntry = errors.New("no matching cache entry") ErrInvalidType = errors.New("cache entry value cannot be converted to requested type") )
Functions ¶
func NewOverwriteError ¶
func NewOverwriteError(existing *CacheResult) error
NewOverwriteError returns a new overwrite error, specifying the existing value in the cache that generated the error.
Types ¶
type AsyncWriter ¶
type AsyncWriter interface { // Queue add a model to an asynchronous write queue. Non-blocking. Queue(ctx context.Context, key cachekey.CacheKey, value any) error // Flush triggers writes of any remaining items in the queue. Blocks until operation completes Flush(ctx context.Context) error // Close cleans up any resources used by the AsyncWriter implementation. Writer cannot be reused after this call. Close(ctx context.Context) error }
AysncWriter defines the interface for writer clients to queue aysnchronous, batched writes to the cache.
type CacheDriver ¶
type CacheDriver interface { services.Dependency // Close cleans up any resources used by the CacheDriver implementation. CacheDriver cannot be reused after this call. Close(ctx context.Context) error }
CacheDriver defines the interface for implementations of the cache provider for intermediate caching of K8s relationship data.
type CacheProvider ¶
type CacheProvider interface { CacheReader // BulkWriter creates a new AsyncWriter instance to enable asynchronous bulk inserts. BulkWriter(ctx context.Context, opts ...WriterOption) (AsyncWriter, error) // Prepare drops all data from the cache (usually to ensure a clean start). Prepare(ctx context.Context) error }
CacheProvider defines the interface for reading and writing data from the cache provider.
func Factory ¶
func Factory(ctx context.Context, cfg *config.KubehoundConfig) (CacheProvider, error)
Factory returns an initialized instance of a cache provider from the provided application config.
type CacheReader ¶
type CacheReader interface { CacheDriver // Get fetches an entry from the cache for the provided cache key. Get(ctx context.Context, key cachekey.CacheKey) *CacheResult }
CacheReader defines the interface for reading data from the cache provider.
type CacheResult ¶
CacheResult provides syntactic sugar around retrieval and type casting of entries from the cache.
func (*CacheResult) Bool ¶
func (r *CacheResult) Bool() (bool, error)
Bool returns the result value as a boolean alongside any errors.
func (*CacheResult) Int64 ¶
func (r *CacheResult) Int64() (int64, error)
Int64 returns the result value as a int64 alongside any errors.
func (*CacheResult) ObjectID ¶
func (r *CacheResult) ObjectID() (primitive.ObjectID, error)
ObjectID returns the result value as a bson ObjectID alongside any errors.
func (*CacheResult) Role ¶
func (r *CacheResult) Role() (*store.Role, error)
Text returns the result value as a string alongside any errors.
func (*CacheResult) Text ¶
func (r *CacheResult) Text() (string, error)
Text returns the result value as a string alongside any errors.
type MemCacheAsyncWriter ¶
type MemCacheAsyncWriter struct {
// contains filtered or unexported fields
}
type MemCacheProvider ¶
type MemCacheProvider struct {
// contains filtered or unexported fields
}
func NewMemCacheProvider ¶
func NewMemCacheProvider(ctx context.Context) (*MemCacheProvider, error)
NewMemCacheProvider returns a new cache provider based on a simple in-memory map.
func (*MemCacheProvider) BulkWriter ¶
func (m *MemCacheProvider) BulkWriter(ctx context.Context, opts ...WriterOption) (AsyncWriter, error)
func (*MemCacheProvider) Get ¶
func (m *MemCacheProvider) Get(ctx context.Context, key cachekey.CacheKey) *CacheResult
func (*MemCacheProvider) HealthCheck ¶
func (m *MemCacheProvider) HealthCheck(ctx context.Context) (bool, error)
func (*MemCacheProvider) Name ¶
func (mp *MemCacheProvider) Name() string
type OverwriteError ¶
type OverwriteError struct {
// contains filtered or unexported fields
}
OverwriteError is a custom error type used by the cache implementation is an overwrite occurs when the WithTest option is set.
func (OverwriteError) Error ¶
func (e OverwriteError) Error() string
Error implements the standard error interface.
func (OverwriteError) Existing ¶
func (e OverwriteError) Existing() *CacheResult
Existing returns the existing value in the cache that generated the error.
type WriterOption ¶
type WriterOption func(*writerOptions)
func WithExpectedOverwrite ¶
func WithExpectedOverwrite() WriterOption
WithExpectedOverwrite signals that overwriting values is expected and suppresses logs & metrics generation. Mutually exclusive with WithTest.
func WithTest ¶
func WithTest() WriterOption
Perform a test and set operation on writes. Only set the value if it does not currently exist. If the value does exist, return an ErrCacheEntryOverwrite error. Mutually exclusive with WithExpectedOverwrite.