UNPKG

nostr-deploy-server

Version:

Node.js server for hosting static websites under npub subdomains using Nostr protocol and Blossom servers

96 lines 4.54 kB
import Keyv from 'keyv'; import { ParsedEvent } from '../types'; export declare const getCacheInstances: () => Promise<{ /** A cache that maps a domain to a pubkey ( domain -> pubkey ) */ pubkeyDomains: Keyv<string | undefined>; /** A cache that maps a pubkey to a set of blossom servers ( pubkey -> servers ) */ pubkeyServers: Keyv<string[] | undefined>; /** A cache that maps a pubkey to a set of relays ( pubkey -> relays ) */ pubkeyRelays: Keyv<string[] | undefined>; /** A cache that maps a pubkey + path to sha256 hash of the blob ( pubkey/path -> sha256 ) */ pathBlobs: Keyv<ParsedEvent | undefined>; /** A cache that maps a sha256 hash to a set of URLs that had the blob ( sha256 -> URLs ) */ blobURLs: Keyv<string[] | undefined>; /** A cache for file content */ fileContent: Keyv<Uint8Array<ArrayBufferLike> | undefined>; /** A cache for negative results (not found) */ negativeCache: Keyv<boolean | undefined>; }>; export declare class CacheService { private static caches; private static getCaches; /** * Get value from cache and optionally refresh TTL (sliding expiration) */ private static getWithSlidingExpiration; /** * Touch multiple cache entries to refresh their TTL * Used when accessing a domain triggers refresh of all related cache entries */ private static touchRelatedCacheEntries; static getPubkeyForDomain(domain: string): Promise<string | null>; static setPubkeyForDomain(domain: string, pubkey: string): Promise<void>; static getBlossomServersForPubkey(pubkey: string): Promise<string[] | null>; static setBlossomServersForPubkey(pubkey: string, servers: string[]): Promise<void>; static getRelaysForPubkey(pubkey: string): Promise<string[] | null>; static setRelaysForPubkey(pubkey: string, relays: string[]): Promise<void>; static getBlobForPath(pubkey: string, path: string): Promise<ParsedEvent | null>; static setBlobForPath(pubkey: string, path: string, event: ParsedEvent): Promise<void>; static invalidateBlobForPath(pubkey: string, path: string): Promise<void>; static getBlobURLs(sha256: string): Promise<string[] | null>; static setBlobURLs(sha256: string, urls: string[]): Promise<void>; static getFileContent(sha256: string): Promise<Uint8Array | null>; static setFileContent(sha256: string, content: Uint8Array): Promise<void>; static isNegativeCached(key: string): Promise<boolean>; static setNegativeCache(key: string): Promise<void>; static clearAll(): Promise<void>; static getStats(): Promise<Record<string, any>>; /** * Invalidate relay list cache for a specific pubkey * Used by real-time cache invalidation when relay list events are received */ static invalidateRelaysForPubkey(pubkey: string): Promise<void>; /** * Invalidate blossom server list cache for a specific pubkey * Used by real-time cache invalidation when blossom server events are received */ static invalidateBlossomServersForPubkey(pubkey: string): Promise<void>; /** * Invalidate all cache entries for a specific pubkey * Nuclear option for when we want to clear everything related to a user */ static invalidateAllForPubkey(pubkey: string): Promise<void>; /** * Invalidate negative cache entries * Useful when we know data has been published that was previously missing */ static invalidateNegativeCache(pattern?: string): Promise<void>; /** * Main method for handling domain access with sliding expiration * This method should be called when a user accesses a domain * It refreshes TTL for all related cache entries */ static handleDomainAccess(domain: string, pubkey: string): Promise<void>; } export declare class MemoryCache<T> { private cache; private maxSize; private defaultTtl; private cleanupInterval; constructor(); set(key: string, value: T, ttl?: number): void; get(key: string): T | null; has(key: string): boolean; delete(key: string): boolean; clear(): void; size(): number; keys(): string[]; private isExpired; private cleanup; destroy(): void; } export declare const pathMappingCache: MemoryCache<string>; export declare const relayListCache: MemoryCache<string[]>; export declare const blossomServerCache: MemoryCache<string[]>; export declare const fileContentCache: MemoryCache<Uint8Array<ArrayBufferLike>>; //# sourceMappingURL=cache.d.ts.map