cache

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

client/cache/cache.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheUserDataFromObjects

func CacheUserDataFromObjects(publicKey string, metadata *nostr.Event, mailboxes *core.Mailboxes)

CacheUserDataFromObjects caches user metadata and mailboxes from Go objects

func CleanupExpired

func CleanupExpired()

CleanupExpired removes all expired entries from cache

func ClearUserData

func ClearUserData(publicKey string)

ClearUserData removes a specific user from cache

func GetCacheExpiry

func GetCacheExpiry() time.Duration

GetCacheExpiry returns the current cache expiry duration

func GetCacheStats

func GetCacheStats() map[string]interface{}

GetCacheStats returns statistics about the cache

func GetParsedUserData

func GetParsedUserData(publicKey string) (*nostr.Event, *core.Mailboxes, bool)

GetParsedUserData retrieves and parses cached user data

func IsExpiringSoon

func IsExpiringSoon(publicKey string, within time.Duration) bool

IsExpiringSoon checks if cache will expire within the given duration

func IsValidCachedData

func IsValidCachedData(cachedData CachedUserData) bool

IsValidCachedData checks if cached data contains valid user information

func SetCacheExpiry

func SetCacheExpiry(duration time.Duration)

SetCacheExpiry allows dynamic configuration of cache expiry

func SetUserData

func SetUserData(publicKey string, metadata, mailboxes string)

SetUserData stores user metadata and mailbox data in cache

func StartCacheCleanup

func StartCacheCleanup()

startCacheCleanup starts a background goroutine to clean up expired cache entries

Types

type CachedUserData

type CachedUserData struct {
	Metadata  string    // JSON serialized metadata (kind 0 event)
	Mailboxes string    // JSON serialized mailboxes (kind 10002 relay list)
	Timestamp time.Time // Time of insertion for expiration
}

CachedUserData holds user metadata and mailbox information

func GetUserData

func GetUserData(publicKey string) (CachedUserData, bool)

GetUserData retrieves cached user data if not expired

func GetUserDataWithAge

func GetUserDataWithAge(publicKey string) (CachedUserData, time.Duration, bool)

GetUserDataWithAge retrieves cached user data with age information Useful for determining if refresh is needed soon

type UserCache

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

UserCache manages in-memory user data with automatic expiration

Jump to

Keyboard shortcuts

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