Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

260
Visualizações
Firestore (Web version 9 modular): getDocsFromCache seems not working

I'm new to Firebase and I found getDocsFromCache. I heard that firebase updated it's version to version 9, (modular) and i have to use more than just query.get({source: "cache"}). But getDocsFromCache didn't work for me. Every time i call getDocsFromCache, it does not throw any errors but snapshot.empty is always true so i can't access to my documents(collection).

If i have to cache manually, how? If not, what am i missing?

Thank you.

import {
 ​collection,
 ​getDocs,
 ​getDocsFromCache,
 ​query,
} from 'firebase/firestore';
import { db } from '../firebase-config';

export const getReviews = async () => {
 ​const q = query(collection(db, 'review'));

 ​try {
   ​const snapshot = await getDocsFromCache(q);

   ​console.log(snapshot.empty);   // always true but not throwing any error

   ​snapshot.forEach((doc) => {
     ​/* ... */
   ​});

 ​} catch (e) {
   // never reach here
   ​const snapshot = await getDocs(q);

   /* ... */
 ​}
};
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

From the documentation on configuring offline persistence:

For the web, offline persistence is disabled by default. To enable persistence, call the enablePersistence method.

So make sure to enable the cache by calling this right after initializing Firebase and Firestore:

import { enableIndexedDbPersistence } from "firebase/firestore"; 

enableIndexedDbPersistence(db);
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda