Documentation
¶
Overview ¶
Package cache provides efficient caching mechanisms for federation operations, particularly focused on caching public keys and instance metadata to improve ActivityPub federation performance and reduce external API calls.
Index ¶
- type ActorEntry
- type Config
- type FederationCache
- func (fc *FederationCache) Clear()
- func (fc *FederationCache) Close()
- func (fc *FederationCache) GetActor(actorID string) (*ActorEntry, bool)
- func (fc *FederationCache) GetInstance(domain string) (*InstanceEntry, bool)
- func (fc *FederationCache) GetOrFetchInstance(domain string, fetchFn func() (map[string]interface{}, bool, error)) (*InstanceEntry, error)
- func (fc *FederationCache) GetOrFetchPublicKey(keyID string, fetchFn func() (crypto.PublicKey, string, string, error)) (crypto.PublicKey, error)
- func (fc *FederationCache) GetPublicKey(keyID string) (*PublicKeyEntry, bool)
- func (fc *FederationCache) GetStats() Stats
- func (fc *FederationCache) InvalidateActor(actorID string)
- func (fc *FederationCache) InvalidateInstance(domain string)
- func (fc *FederationCache) InvalidatePublicKey(keyID string)
- func (fc *FederationCache) SetActor(actorID, username, domain, publicKeyID string, profile map[string]interface{})
- func (fc *FederationCache) SetInstance(domain string, metadata map[string]interface{}, available bool)
- func (fc *FederationCache) SetPublicKey(keyID string, key crypto.PublicKey, owner, algorithm string)
- type InstanceEntry
- type PublicKeyEntry
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActorEntry ¶
type ActorEntry struct {
ActorID string `json:"actor_id"`
Username string `json:"username"`
Domain string `json:"domain"`
PublicKeyID string `json:"public_key_id"`
Profile map[string]interface{} `json:"profile"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
ActorEntry represents a cached actor profile
type Config ¶
type Config struct {
// Size is the maximum number of items in the cache
Size int `json:"size"`
}
Config holds configuration for FederationCache
func DefaultCacheConfig ¶
func DefaultCacheConfig() Config
DefaultCacheConfig returns sensible defaults for federation caching
type FederationCache ¶
type FederationCache struct {
// contains filtered or unexported fields
}
FederationCache provides caching for federation-related data with TTL support
func NewFederationCache ¶
func NewFederationCache(config Config, storage interface{}, logger *zap.Logger) *FederationCache
NewFederationCache creates a new federation cache with the given configuration
func (*FederationCache) Clear ¶
func (fc *FederationCache) Clear()
Clear removes all entries from the cache
func (*FederationCache) Close ¶
func (fc *FederationCache) Close()
Close stops the cache cleanup goroutine and cleans up resources
func (*FederationCache) GetActor ¶
func (fc *FederationCache) GetActor(actorID string) (*ActorEntry, bool)
GetActor retrieves a cached actor profile by actor ID
func (*FederationCache) GetInstance ¶
func (fc *FederationCache) GetInstance(domain string) (*InstanceEntry, bool)
GetInstance retrieves cached instance metadata by domain
func (*FederationCache) GetOrFetchInstance ¶
func (fc *FederationCache) GetOrFetchInstance(domain string, fetchFn func() (map[string]interface{}, bool, error)) (*InstanceEntry, error)
GetOrFetchInstance attempts to get from cache, falls back to fetch function if not found
func (*FederationCache) GetOrFetchPublicKey ¶
func (fc *FederationCache) GetOrFetchPublicKey(keyID string, fetchFn func() (crypto.PublicKey, string, string, error)) (crypto.PublicKey, error)
GetOrFetchPublicKey attempts to get from cache, falls back to fetch function if not found
func (*FederationCache) GetPublicKey ¶
func (fc *FederationCache) GetPublicKey(keyID string) (*PublicKeyEntry, bool)
GetPublicKey retrieves a cached public key by key ID
func (*FederationCache) GetStats ¶
func (fc *FederationCache) GetStats() Stats
GetStats returns cache statistics
func (*FederationCache) InvalidateActor ¶
func (fc *FederationCache) InvalidateActor(actorID string)
InvalidateActor removes an actor profile from the cache
func (*FederationCache) InvalidateInstance ¶
func (fc *FederationCache) InvalidateInstance(domain string)
InvalidateInstance removes instance metadata from the cache
func (*FederationCache) InvalidatePublicKey ¶
func (fc *FederationCache) InvalidatePublicKey(keyID string)
InvalidatePublicKey removes a public key from the cache
func (*FederationCache) SetActor ¶
func (fc *FederationCache) SetActor(actorID, username, domain, publicKeyID string, profile map[string]interface{})
SetActor stores an actor profile in the cache
func (*FederationCache) SetInstance ¶
func (fc *FederationCache) SetInstance(domain string, metadata map[string]interface{}, available bool)
SetInstance stores instance metadata in the cache
func (*FederationCache) SetPublicKey ¶
func (fc *FederationCache) SetPublicKey(keyID string, key crypto.PublicKey, owner, algorithm string)
SetPublicKey stores a public key in the cache
type InstanceEntry ¶
type InstanceEntry struct {
Domain string `json:"domain"`
Metadata map[string]interface{} `json:"metadata"`
Available bool `json:"available"`
LastChecked time.Time `json:"last_checked"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
InstanceEntry represents cached instance metadata
type PublicKeyEntry ¶
type PublicKeyEntry struct {
Key crypto.PublicKey `json:"key"`
KeyID string `json:"key_id"`
Owner string `json:"owner"` // Actor URI who owns this key
Algorithm string `json:"algorithm"` // Key algorithm (RSA, Ed25519, etc.)
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
PublicKeyEntry represents a cached public key with metadata
type Stats ¶
type Stats struct {
Size int `json:"size"`
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Evictions int64 `json:"evictions"`
TotalGets int64 `json:"total_gets"`
TotalSets int64 `json:"total_sets"`
TotalInvalidates int64 `json:"total_invalidates"`
}
Stats holds cache usage statistics