cache

package
v0.3.58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY_LOCK_SUFFIX = "_locked" // Suffix appended to cache keys for locking purposes
)

Variables

This section is empty.

Functions

func SetLog

func SetLog(l dependency.ILog)

SetLog sets the logging dependency. Parameters: l - represents the logging dependency interface, used to unify the logging method This function does not return any value.

func Shell

func Shell[T any](ctx context.Context, request dependency.ICacheShellKey, f func() (T, exception.Exception), opts ...ShellOptionFunc) (T, exception.Exception)

Shell is a generic function that executes caching logic. @param ctx The context for logging and cancellation purposes. @param request The cache key request interface to get the cache key. @param f A function executed when cache is missed or unavailable, generating the result. @param opts One or more ShellOptionFuncs to further configure the Shell options. @return Returns the result of function f and a possible exception.

func ShellClear

func ShellClear(request dependency.ICacheShellKey, opts ...ShellOptionFunc) exception.Exception

ShellClear clears the specified cache key and its lock identifier. @param cache The cache instance to perform cache operations. @param request The cache key request interface to get the cache key. @param opts One or more ShellOptionFuncs to further configure the Shell options. @return An exception instance if there's an error clearing the cache.

Types

type ShellOptionFunc

type ShellOptionFunc func(option *ShellOptions)

ShellOptionFunc is a function type that configures ShellOptions.

func WithCache

func WithCache(cache dependency.ICache) ShellOptionFunc

WithCache provides an option to customize the cache instance. @return A ShellOptionFunc to set the cache instance.

func WithDuration

func WithDuration(dur time.Duration) ShellOptionFunc

WithDuration provides an option to customize the cache duration. @return A ShellOptionFunc to set the cache duration.

func WithKey

func WithKey(key string) ShellOptionFunc

WithKey provides an option to customize the cache key. @return A ShellOptionFunc to set the cache key.

func WithSkip

func WithSkip(skip bool) ShellOptionFunc

WithSkip provides an option to skip caching. @return A ShellOptionFunc to set whether to skip caching.

type ShellOptions

type ShellOptions struct {
	// contains filtered or unexported fields
}

ShellOptions defines configuration options for shell operations.

func NewShellOptions

func NewShellOptions(cache dependency.ICache, request dependency.ICacheShellKey, opts ...ShellOptionFunc) *ShellOptions

NewShellOptions initializes and returns a new ShellOptions instance. @param cache The dependency cache interface used for cache operations. @param request The dependency cache key request interface, used to retrieve cache keys and durations. @param opts One or more ShellOptionFuncs to further configure the Shell options. @return A configured ShellOptions instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL