feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Cache advisors for a week / allow them to refresh said cache

This commit is contained in:
Dave
2025-11-07 12:26:25 -05:00
parent b0b73f1af8
commit 9ce022b5e8
3 changed files with 152 additions and 20 deletions

View File

@@ -2,6 +2,10 @@ const { GET_BODYSHOP_BY_ID } = require("../graphql-client/queries");
const devDebugLogger = require("./devDebugLogger");
const client = require("../graphql-client/graphql-client").client;
/**
* Bodyshop cache TTL in seconds
* @type {number}
*/
const BODYSHOP_CACHE_TTL = 3600; // 1 hour
/**
@@ -63,7 +67,12 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
}
};
// Retrieve session data from Redis
/**
* Retrieve session data from Redis
* @param socketId
* @param key
* @returns {Promise<any|null>}
*/
const getSessionData = async (socketId, key) => {
try {
const data = await pubClient.hget(`socket:${socketId}`, key);
@@ -73,6 +82,15 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
}
};
/**
* Store session transaction data in Redis
* @param socketId
* @param transactionType
* @param key
* @param value
* @param ttl
* @returns {Promise<void>}
*/
const setSessionTransactionData = async (socketId, transactionType, key, value, ttl) => {
try {
await pubClient.hset(getSocketTransactionkey({ socketId, transactionType }), key, JSON.stringify(value)); // Use Redis pubClient
@@ -88,7 +106,13 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
}
};
// Retrieve session transaction data from Redis
/**
* Retrieve session transaction data from Redis
* @param socketId
* @param transactionType
* @param key
* @returns {Promise<any|null>}
*/
const getSessionTransactionData = async (socketId, transactionType, key) => {
try {
const data = await pubClient.hget(getSocketTransactionkey({ socketId, transactionType }), key);
@@ -102,7 +126,11 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
}
};
// Clear session data from Redis
/**
* Clear session data from Redis
* @param socketId
* @returns {Promise<void>}
*/
const clearSessionData = async (socketId) => {
try {
await pubClient.del(`socket:${socketId}`);
@@ -110,7 +138,13 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
logger.log(`Error Clearing Session Data for socket ${socketId}: ${error}`, "ERROR", "redis");
}
};
// Clear session data from Redis
/**
* Clear session transaction data from Redis
* @param socketId
* @param transactionType
* @returns {Promise<void>}
*/
const clearSessionTransactionData = async (socketId, transactionType) => {
try {
await pubClient.del(getSocketTransactionkey({ socketId, transactionType }));
@@ -321,8 +355,22 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
}
};
/**
* Set provider cache data
* @param ns
* @param field
* @param value
* @param ttl
* @returns {Promise<void>}
*/
const setProviderCache = (ns, field, value, ttl) => setSessionData(`${ns}:provider`, field, value, ttl);
/**
* Get provider cache data
* @param ns
* @param field
* @returns {Promise<any|null|undefined>}
*/
const getProviderCache = (ns, field) => getSessionData(`${ns}:provider`, field);
const api = {