diff --git a/packages/sdk/src/contracts/StreamRegistry.ts b/packages/sdk/src/contracts/StreamRegistry.ts index 696c191429..04a31edd90 100644 --- a/packages/sdk/src/contracts/StreamRegistry.ts +++ b/packages/sdk/src/contracts/StreamRegistry.ts @@ -126,10 +126,10 @@ export class StreamRegistry { private readonly config: Pick private readonly authentication: Authentication private readonly logger: Logger - private readonly getStreamMetadata_cached: CachingMap - private readonly isStreamPublisher_cached: CachingMap - private readonly isStreamSubscriber_cached: CachingMap - private readonly hasPublicSubscribePermission_cached: CachingMap + private readonly metadataCache: CachingMap + private readonly publisherCache: CachingMap + private readonly subscriberCache: CachingMap + private readonly publicSubscribePermissionCache: CachingMap /** @internal */ constructor( @@ -170,25 +170,25 @@ export class StreamRegistry { }), loggerFactory }) - this.getStreamMetadata_cached = new CachingMap((streamId: StreamID) => { + this.metadataCache = new CachingMap((streamId: StreamID) => { return this.getStreamMetadata_nonCached(streamId) }, { ...config.cache, cacheKey: ([streamId]) => formCacheKeyPrefix(streamId) }) - this.isStreamPublisher_cached = new CachingMap((streamId: StreamID, userId: UserID) => { + this.publisherCache = new CachingMap((streamId: StreamID, userId: UserID) => { return this.isStreamPublisherOrSubscriber_nonCached(streamId, userId, StreamPermission.PUBLISH) }, { ...config.cache, cacheKey: ([streamId, userId]) =>`${formCacheKeyPrefix(streamId)}${userId}` }) - this.isStreamSubscriber_cached = new CachingMap((streamId: StreamID, userId: UserID) => { + this.subscriberCache = new CachingMap((streamId: StreamID, userId: UserID) => { return this.isStreamPublisherOrSubscriber_nonCached(streamId, userId, StreamPermission.SUBSCRIBE) }, { ...config.cache, cacheKey: ([streamId, userId]) =>`${formCacheKeyPrefix(streamId)}${userId}` }) - this.hasPublicSubscribePermission_cached = new CachingMap((streamId: StreamID) => { + this.publicSubscribePermissionCache = new CachingMap((streamId: StreamID) => { return this.hasPermission({ streamId, public: true, @@ -275,7 +275,7 @@ export class StreamRegistry { streamId, ethersOverrides )) - invalidateCache(this.getStreamMetadata_cached, streamId) + invalidateCache(this.metadataCache, streamId) this.invalidatePermissionCaches(streamId) } @@ -519,37 +519,37 @@ export class StreamRegistry { async getStreamMetadata(streamId: StreamID, useCache = true): Promise { if (!useCache) { - invalidateCache(this.getStreamMetadata_cached, streamId) + invalidateCache(this.metadataCache, streamId) } - return this.getStreamMetadata_cached.get(streamId) + return this.metadataCache.get(streamId) } isStreamPublisher(streamId: StreamID, userId: UserID, useCache = true): Promise { if (useCache) { - invalidateCache(this.isStreamPublisher_cached, streamId) + invalidateCache(this.publisherCache, streamId) } - return this.isStreamPublisher_cached.get(streamId, userId) + return this.publisherCache.get(streamId, userId) } isStreamSubscriber(streamId: StreamID, userId: UserID, useCache = true): Promise { if (useCache) { - invalidateCache(this.isStreamSubscriber_cached, streamId) + invalidateCache(this.subscriberCache, streamId) } - return this.isStreamSubscriber_cached.get(streamId, userId) + return this.subscriberCache.get(streamId, userId) } hasPublicSubscribePermission(streamId: StreamID): Promise { - return this.hasPublicSubscribePermission_cached.get(streamId) + return this.publicSubscribePermissionCache.get(streamId) } private populateMetadataCache(streamId: StreamID, metadata: StreamMetadata): void { - this.getStreamMetadata_cached.set([streamId], metadata) + this.metadataCache.set([streamId], metadata) } invalidatePermissionCaches(streamId: StreamID): void { this.logger.trace('Clear permission caches for stream', { streamId }) - invalidateCache(this.isStreamPublisher_cached, streamId) - invalidateCache(this.isStreamSubscriber_cached, streamId) + invalidateCache(this.publisherCache, streamId) + invalidateCache(this.subscriberCache, streamId) // TODO should also clear cache for hasPublicSubscribePermission? } }