When working with Firebase Cloud Functions, managing Firestore data efficiently can be tricky. The @libs-jd/cloud-firestore-cache library offers a simple solution for caching Firestore data within a single cloud function instance.
This library provides a caching mechanism specifically designed for cloud functions configured with maxInstances
set to 1. In this scenario, all requests are handled by a single server instance, allowing for an in-memory caching strategy.
Scoped Caching: Works within a single cloud function instance
Simplified Firestore Operations: Wrapper around standard Firestore methods
Minimal Performance Overhead: Lightweight caching mechanism
📦 Github: https://github.com/jeet-dhandha/cloud-firestore-cache
🔗 NPM: https://www.npmjs.com/package/@libs-jd/cloud-firestore-cache
npm install @libs-jd/cloud-firestore-cache
const { initializeApp } = require("firebase-admin/app");
const { getFirestore, FieldValue } = require("firebase-admin/firestore");
const { FirestoreCache } = require("@libs-jd/cloud-firestore-cache");
initializeApp();
const firestoreInstance = getFirestore();
const db = FirestoreCache(firestoreInstance, FieldValue);
// Cached Firestore operations
db.get("users/user123").then((result) => {
console.log("Cached or fetched result:", result);
});
Single Instance Limitation: Most effective when maxInstances
is set to 1
In-Memory Caching: Cache is maintained within the function's lifecycle
Early Stage Library: Currently in alpha, expect potential changes
This library is particularly useful in scenarios where:
You have a cloud function with a single instance
You want to reduce redundant Firestore reads
You're looking for a simple caching mechanism with minimal configuration
Reduced Firestore read operations
Slight performance improvement for repeated data access
Simplified caching logic
Not suitable for multi-instance deployments
Cache is ephemeral and resets with function cold starts
Limited to basic caching strategies
Note: This library addresses a specific caching need in Firebase Cloud Functions. Evaluate its suitability for your specific use case.
Join Jeet on Peerlist!
Join amazing folks like Jeet and thousands of other people in tech.
Create ProfileJoin with Jeet’s personal invite link.
0
8
0