inmemory

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemory

type InMemory struct {
	Options Options
	// contains filtered or unexported fields
}

InMemory is an in-memory `cache.Backend`.

func New

func New(ctx context.Context, opts ...Option) (*InMemory, error)

New creates a new in-memory `cache.Backend` implementation with the supplied options. Note that this starts a go-routine to evict expired items from the cache. This go-routine is terminated when the context is cancelled.

func (*InMemory) Get

Get a value from the cache. If the key is not found, return `nil`.

func (*InMemory) Put

func (im *InMemory) Put(_ context.Context, key string, value *llms.ContentResponse)

Put a value into the cache.

type Option

type Option func(*Options) error

Option is a functional argument that configures the Options.

func WithCacheOptions

func WithCacheOptions(opts ...cache.Option[string, *llms.ContentResponse]) Option

WithCacheOptions specifies the options for the underlying cache. Note: multiple instances are appended, so `New(ctx, WithCacheOptions(opt1, opt2))` is the same as `New(ctx, WithCacheOptions(opt1), WithCacheOptions(opt2))`.

func WithExpiration

func WithExpiration(expiration time.Duration) Option

WithExpiration specifies the time-to-live for specific items that are added to the cache. This is the same as: `WithItemOptions(cache.WithExpiration(expiration))`.

func WithItemOptions

func WithItemOptions(opts ...cache.ItemOption) Option

WithItemOptions specifies the options for the underlying cache for each specific item that is added. Note: multiple instances are appended, so `New(ctx, WithItemOptions(opt1, opt2))` is the same as `New(ctx, WithItemOptions(opt1), WithItemOptions(opt2))`.

type Options

type Options struct {
	CacheOptions []cache.Option[string, *llms.ContentResponse]
	ItemOptions  []cache.ItemOption
}

Options is a set of options for the in-memory cache.

Jump to

Keyboard shortcuts

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