cache

package
v0.4.12 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClientRelay added in v0.4.12

func AddClientRelay(publicKey, relayURL string) error

Legacy function for backward compatibility

func AddClientRelayWithPermissions added in v0.4.12

func AddClientRelayWithPermissions(publicKey, relayURL string, read, write bool) error

AddClientRelayWithPermissions adds a client relay with specific permissions

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 ClearClientRelays added in v0.4.12

func ClearClientRelays(publicKey string)

ClearClientRelays clears all client relays for a user

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 GetClientRelays added in v0.4.12

func GetClientRelays(publicKey string) []string

GetClientRelays returns user's cached client relays (legacy format)

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 RemoveClientRelay added in v0.4.12

func RemoveClientRelay(publicKey, relayURL string) error

RemoveClientRelay removes a specific relay from user's client relay list

func SetCacheExpiry

func SetCacheExpiry(duration time.Duration)

SetCacheExpiry allows dynamic configuration of cache expiry

func SetUserClientRelaysFromMailboxes added in v0.4.12

func SetUserClientRelaysFromMailboxes(publicKey string) error

SetUserClientRelaysFromMailboxes sets user's client relays from cached mailbox data

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:"metadata"`  // JSON serialized metadata (kind 0 event)
	Mailboxes string    `json:"mailboxes"` // JSON serialized mailboxes (kind 10002 relay list)
	Timestamp time.Time `json:"timestamp"` // 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

type ClientRelayConfig added in v0.4.12

type ClientRelayConfig struct {
	URL       string    `json:"url"`
	Read      bool      `json:"read"`
	Write     bool      `json:"write"`
	Connected bool      `json:"connected"` // Whether the client is connected to this relay
	AddedAt   time.Time `json:"added_at"`  // Time when the relay was added
}

ClientRelayConfig represents relay configuration with permissions

func GetUserClientRelays added in v0.4.12

func GetUserClientRelays(publicKey string) ([]ClientRelayConfig, error)

GetUserClientRelays returns user's client relays in the format expected by the API

func GetUserClientRelaysWithPermissions added in v0.4.12

func GetUserClientRelaysWithPermissions(publicKey string) ([]ClientRelayConfig, error)

GetUserClientRelaysWithPermissions retrieves user's client relays with permissions

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