HcsCacheService API Reference
This document provides a detailed API reference for the HcsCacheService class — a service responsible for caching Hedera Consensus Service (HCS) topic information, messages, and files.
Methods
getTopicInfo
public getTopicInfo(client: Client, topicId: string): Promise<TopicInfo | null>
Retrieves cached topic information for a given client and topic ID.
-
client(required): Hedera SDK client instance associated with the request. -
topicId(required): The ID of the HCS topic.
-
A promise resolving to the cached
TopicInfoif present, ornullif not cached.
setTopicInfo
public setTopicInfo(client: Client, topicId: string, topicInfo: TopicInfo): Promise<void>
Stores topic information in the cache.
-
client(required): Hedera SDK client instance associated with the cache entry. -
topicId(required): The ID of the HCS topic. -
topicInfo(required): TheTopicInfoobject to cache.
-
A promise that resolves when the data is cached.
removeTopicInfo
public async removeTopicInfo(client: Client, topicId: string): Promise<void>
Removes cached topic information and associated messages for a topic.
-
client(required): Hedera SDK client instance. -
topicId(required): The ID of the HCS topic to remove from cache.
-
A promise that resolves when the cache entries have been removed.
getTopicMessages
public getTopicMessages(client: Client, topicId: string): Promise<TopicMessageData[] | null>
Retrieves cached messages for a given topic.
-
client(required): Hedera SDK client instance. -
topicId(required): The ID of the HCS topic.
-
A promise resolving to an array of cached
TopicMessageData, ornullif no cached messages exist.
setTopicMessages
public async setTopicMessages(client: Client, topicId: string, messages: TopicMessageData[]): Promise<void>
Stores an array of topic messages in the cache and removes any cached file for the topic.
-
client(required): Hedera SDK client instance. -
topicId(required): The ID of the HCS topic. -
messages(required): Array ofTopicMessageDatato cache.
-
A promise that resolves when the messages have been cached and related cached files are cleared.
removeTopicMessages
public async removeTopicMessages(client: Client, topicId: string): Promise<void>
Removes cached messages and cached file for a given topic.
-
client(required): Hedera SDK client instance. -
topicId(required): The ID of the HCS topic.
-
A promise that resolves when the cached messages and file for the topic have been removed.
getTopicFile
public getTopicFile(client: Client, topicId: string): Promise<Buffer | null>
Retrieves a cached file buffer for a topic, if available.
-
client(required): Hedera SDK client instance. -
topicId(required): The ID of the HCS topic.
-
A promise resolving to the cached file
Buffer, ornullif none exists.
setTopicFile
public setTopicFile(client: Client, topicId: string, file: Buffer): Promise<void>
Stores a file buffer in the cache for a given topic.
-
client(required): Hedera SDK client instance. -
topicId(required): The ID of the HCS topic. -
file(required): The file contents as aBuffer.
-
A promise that resolves when the file has been cached.
removeTopicFile
public removeTopicFile(client: Client, topicId: string): Promise<void>
Removes a cached file for a given topic.
-
client(required): Hedera SDK client instance. -
topicId(required): The ID of the HCS topic.
-
A promise that resolves when the cached file has been removed.