Skip to content

Commit 84aad1c

Browse files
committed
fix: storage cache cross-process invalidation logic
1 parent 0dac280 commit 84aad1c

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

apps/dashboard-api/src/controllers/project.controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,13 @@ module.exports.updateExternalConfig = async (req, res) => {
780780
if (!project)
781781
return res.status(404).json({ success: false, data: {}, message: "Project not found or access denied." });
782782

783+
await deleteProjectById(project._id.toString());
784+
await deleteProjectByApiKeyCache(project.publishableKey);
785+
await deleteProjectByApiKeyCache(project.secretKey);
786+
if (updateData["resources.storage.config"]) {
787+
storageRegistry.delete(project._id.toString());
788+
}
789+
783790
res.status(200).json({ success: true, data: {}, message: "External configuration updated successfully." });
784791
} catch (err) {
785792
if (err instanceof z.ZodError) {

packages/common/src/utils/storage.manager.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ async function getStorage(project) {
115115

116116
const key = project._id.toString();
117117

118+
const currentConfigStr = project.resources?.storage?.config;
119+
118120
// CACHE - REUSE EXISTING CLIENT
119121
if (storageRegistry.has(key)) {
120122
const entry = storageRegistry.get(key);
121-
entry.lastUsed = Date.now();
122-
return entry.client;
123+
if (entry.configStr === currentConfigStr) {
124+
entry.lastUsed = Date.now();
125+
return entry.client;
126+
}
123127
}
124128

125129
let client;
@@ -160,6 +164,7 @@ async function getStorage(project) {
160164
// REGISTRY - REGISTER CLIENT FOR POOLING
161165
storageRegistry.set(key, {
162166
client,
167+
configStr: currentConfigStr,
163168
lastUsed: Date.now(),
164169
isExternal: !!project.resources?.storage?.isExternal
165170
});

0 commit comments

Comments
 (0)