somod-chat-service
Version:
Serverless Chat Service from SOMOD
19 lines (18 loc) • 719 B
JavaScript
import { DynamoDBClient, GetItemCommand } from "@aws-sdk/client-dynamodb";
import { cache } from "./cache";
import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
const dynamodb = new DynamoDBClient();
const _threadCache = cache(100, 60 * 60000);
export const threadCache = {
get: async (threadId, ttl) => {
return await _threadCache.get(threadId, async () => {
const threadResult = await dynamodb.send(new GetItemCommand({
TableName: process.env.THREAD_TABLE_NAME,
Key: marshall({ id: threadId })
}));
return threadResult.Item
? unmarshall(threadResult.Item)
: undefined;
}, ttl);
}
};