I have implemented a leaderboard using firebase firestore and functions. I want to cache the output of the function and serve applications using this function through cache. Let’s say I cache it for 3 hours. Is there a method to achieve this on firebase using callable functions? and My app is built with flutter.
exports.getScores = functions
.runWith({
enforceAppCheck: true, // Reject requests with missing or invalid App Check tokens.
})
.https.onCall(async (data, context) => {
console.log('enforceAppCheck');
try {
const scoreQ = await admin.firestore().collection("players")
.orderBy("score", "desc")
.limit(7)
.get();
return scoreQ.docs.map((doc) => {
return {
player: doc.id,
score: doc.data().score,
mates: doc.data().checkmates,
kos: doc.data().knockouts,
level: doc.data().level,
};
});
} catch (e) {
functions.logger.log("error occured", e);
return (e);
}
});