cache

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache provides a simple in-file cache implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a generic cache implementation that stores data in files.

func New

func New[T any](baseDir string, cacheType Type) (*Cache[T], error)

New creates a new cache instance with the specified base directory and cache type.

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(id string) error

Delete removes a cached item by its ID.

func (*Cache[T]) Read

func (c *Cache[T]) Read(id string, readFn func(io.Reader) error) error

func (*Cache[T]) Write

func (c *Cache[T]) Write(id string, writeFn func(io.Writer) error) error

type Conversations

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

Conversations is the conversation cache.

func NewConversations

func NewConversations(dir string) (*Conversations, error)

NewConversations creates a new conversation cache.

func (*Conversations) Delete

func (c *Conversations) Delete(id string) error

Delete a conversation.

func (*Conversations) Read

func (c *Conversations) Read(id string, messages *[]proto.Message) error

func (*Conversations) Write

func (c *Conversations) Write(id string, messages *[]proto.Message) error

type ExpiringCache

type ExpiringCache[T any] struct {
	// contains filtered or unexported fields
}

ExpiringCache is a cache implementation that supports expiration of cached items.

func NewExpiring

func NewExpiring[T any](path string) (*ExpiringCache[T], error)

NewExpiring creates a new cache instance that supports item expiration.

func (*ExpiringCache[T]) Delete

func (c *ExpiringCache[T]) Delete(id string) error

Delete removes an expired cached item by its ID.

func (*ExpiringCache[T]) Read

func (c *ExpiringCache[T]) Read(id string, readFn func(io.Reader) error) error

func (*ExpiringCache[T]) Write

func (c *ExpiringCache[T]) Write(id string, expiresAt int64, writeFn func(io.Writer) error) error

type Type

type Type string

Type represents the type of cache being used.

const (
	ConversationCache Type = "conversations"
	TemporaryCache    Type = "temp"
)

Cache types for different purposes.

Jump to

Keyboard shortcuts

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