Skip to content

Commit

Permalink
refactor: update cache settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vighnesh153 committed Dec 29, 2024
1 parent 1f2eb02 commit c5fe228
Show file tree
Hide file tree
Showing 7 changed files with 830 additions and 365 deletions.
6 changes: 6 additions & 0 deletions tools-nodejs/vighnesh153-astro/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ export const firebaseCollections = {
userIdByUsername: "userId_by_username",
privateContent: "private_content",
};

const dayInMillis = 24 * 3600 * 1000;

export const cacheTtlMillis = {
privateContent: 7 * dayInMillis,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as logger from "firebase-functions/logger";
import { HttpsError, onCall } from "firebase-functions/v2/https";

import { firebaseCollections } from "../../constants";
import { cacheTtlMillis, firebaseCollections } from "../../constants";
import { hasPermission } from "../../permissions/mod";

import { firestoreInstance, storageInstance } from "./init";
Expand Down Expand Up @@ -48,7 +48,9 @@ async function createReadSignedUrl(
internalPath: string,
): Promise<string | null> {
const file = storageInstance.bucket().file(internalPath);
const expirationDate = new Date(Date.now() + dayInMs * 2);
const expirationDate = new Date(
Date.now() + cacheTtlMillis.privateContent + dayInMs,
);

// https://github.com/firebase/firebase-tools/issues/3400#issuecomment-847916638
if (process.env.FUNCTIONS_EMULATOR) {
Expand Down
Loading

0 comments on commit c5fe228

Please sign in to comment.