Documentation ¶
Index ¶
- type LoadableCache
- type Option
- func WithBlock[K comparable, V any]() Option[K, V]
- func WithExpiration[K comparable, V any](exp time.Duration) Option[K, V]
- func WithRefreshAfterWrite[K comparable, V any](f func() map[K]V) Option[K, V]
- func WithSize[K comparable, V any](size int) Option[K, V]
- func WithTracing[K comparable, V any](provider oteltrace.TracerProvider) Option[K, V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LoadableCache ¶
type LoadableCache[K comparable, V any] interface { // Get a value pair to the cache data by key. Get(ctx context.Context, k K) (V, error) // GetALL returns all key-value pairs in the cache data. GetALL(context.Context) map[K]V // Values returns all values in the cache data. Values(context.Context) []V // Set a value pair to the cache data by key. Set(ctx context.Context, k K, v V) error // Purge clears all cache data. Purge(context.Context) // TryPurgeAndReload try to refresh cache data, if refresh result is nil, return false. TryPurgeAndReload(context.Context) bool }
func New ¶
func New[K comparable, V any](opts ...Option[K, V]) LoadableCache[K, V]
type Option ¶
type Option[K comparable, V any] func(*loadableCache[K, V])
func WithBlock ¶
func WithBlock[K comparable, V any]() Option[K, V]
WithBlock block call first RefreshAfterWrite.
func WithExpiration ¶
func WithExpiration[K comparable, V any](exp time.Duration) Option[K, V]
WithExpiration cache expiration, Automatically reload if timeout
func WithRefreshAfterWrite ¶
func WithRefreshAfterWrite[K comparable, V any](f func() map[K]V) Option[K, V]
WithRefreshAfterWrite refresh data provider
func WithSize ¶
func WithSize[K comparable, V any](size int) Option[K, V]
WithSize cache size limit.
func WithTracing ¶
func WithTracing[K comparable, V any](provider oteltrace.TracerProvider) Option[K, V]
WithTracing enable otel tracing
Click to show internal directories.
Click to hide internal directories.