ai

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RefreshIntervals = map[string]time.Duration{
	"profile_day":      4 * time.Hour,
	"profile_week":     3 * 24 * time.Hour,
	"profile_month":    7 * 24 * time.Hour,
	"profile_year":     7 * 24 * time.Hour,
	"profile_all_time": 7 * 24 * time.Hour,
	"playlist":         7 * 24 * time.Hour,
	"nowplaying":       365 * 24 * time.Hour,
}

RefreshIntervals for different cache types and periods

Functions

func GetTTL

func GetTTL(cacheType CacheType, cacheKey string) time.Duration

GetTTL returns the appropriate TTL for a cache type and key

func HashString

func HashString(s string) string

HashString creates an MD5 hash of a string

Types

type CacheEntry

type CacheEntry struct {
	ID          int32
	UserID      int32
	CacheType   string
	CacheKey    string
	PromptHash  string
	DataHash    string
	Response    string
	CreatedAt   time.Time
	ExpiresAt   time.Time
	ListenCount int32
}

CacheEntry represents a cached AI response

type CacheManager

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

CacheManager handles AI cache operations

func NewCacheManager

func NewCacheManager(pool *pgxpool.Pool) *CacheManager

NewCacheManager creates a new cache manager

func (*CacheManager) Get

func (c *CacheManager) Get(ctx context.Context, userID int32, cacheType CacheType, cacheKey string) (*CacheEntry, error)

Get retrieves a cache entry if valid

func (*CacheManager) InvalidateAll

func (c *CacheManager) InvalidateAll(ctx context.Context, userID int32) error

InvalidateAll clears all AI caches for a user

func (*CacheManager) InvalidateByType

func (c *CacheManager) InvalidateByType(ctx context.Context, userID int32, cacheType CacheType) error

InvalidateByType clears all caches of a specific type for a user

func (*CacheManager) IsValid

func (c *CacheManager) IsValid(entry *CacheEntry, currentPromptHash, currentDataHash string) bool

IsValid checks if cache entry is still valid based on prompt, data, and expiration

func (*CacheManager) Set

func (c *CacheManager) Set(ctx context.Context, userID int32, cacheType CacheType, cacheKey, promptHash, dataHash, response string, ttl time.Duration, listenCount int32) error

Set stores a cache entry

type CacheType

type CacheType string

CacheType defines the type of AI cache

const (
	CacheTypeProfile    CacheType = "profile"
	CacheTypeNowPlaying CacheType = "nowplaying"
	CacheTypePlaylist   CacheType = "playlist"
)

type PresenceManager

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

PresenceManager tracks active user sessions

func NewPresenceManager

func NewPresenceManager(pool *pgxpool.Pool) *PresenceManager

NewPresenceManager creates a new presence manager

func (*PresenceManager) Cleanup

func (p *PresenceManager) Cleanup(ctx context.Context) error

Cleanup removes old presence records (older than 5 minutes)

func (*PresenceManager) GetLastPing

func (p *PresenceManager) GetLastPing(ctx context.Context, userID int32) (*time.Time, error)

GetLastPing returns when the user was last active

func (*PresenceManager) IsOnline

func (p *PresenceManager) IsOnline(ctx context.Context, userID int32) (bool, error)

IsOnline checks if a user has pinged within the last 30 seconds

func (*PresenceManager) Ping

func (p *PresenceManager) Ping(ctx context.Context, userID int32) error

Ping updates the user's last activity timestamp

Jump to

Keyboard shortcuts

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