Back

Cache seems not clear when using API Key with node-appwrite

  • 0
  • Self Hosted
  • Web
  • Cloud
Suiii
24 Jul, 2024, 13:26
TypeScript
async function createAdminClient() {
    const client = new AppwriteClient();
  
    client
      .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
      .setProject(process.env.NEXT_PUBLIC_PROJECT_ID as string)
      .setKey(process.env.AUTH_SESSION_KEY as string);
  
    return {
      account: new Account(client),
      users: new Users(client), 
      teams: new Teams(client),
      functions: new Functions(client),
      databases: new Databases(client),
    };
  };

const createAdminDB = async () => {
    const { databases } = await createAdminClient();
  
    const db = {} as DB;
  
    collections.forEach((col: Collection) => {
      db[col.name as keyof DB] = {
        create: (payload: any, permissions: string[], id = ID.unique()) =>
          databases.createDocument(
            col.dbId,
            col.id,
            id,
            payload,
            permissions
          ),
        update: (id: string, payload: any, permissions: string[]) =>
          databases.updateDocument(
            col.dbId,
            col.id,
            id,
            payload,
            permissions
          ),
        delete: (id: string) => databases.deleteDocument(col.dbId, col.id, id),
        list: (queries = []) =>
          databases.listDocuments(col.dbId, col.id, queries),
        get: (id: string) => databases.getDocument(col.dbId, col.id, id),
      };
    });
  
    return db;
  };
  
  export { createAdminClient, createAdminDB};

and I have logic here to query some data

TypeScript
const db = await createAdminDB();
    const promise: any = await db.clients.list([
      Query.orderDesc("code"),
      Query.limit(1),
    ]);
    console.log(promise)

when I console log. it always get result which is not existed, as I already deleted

TL;DR
Developers facing issue with caching with API key usage in a node.js app with Appwrite. The problem is related to outdated results being returned despite deletion of data. Solution: Explicitly clear cache or refresh the cache when fetching data to ensure accurate and up-to-date results.
Suiii
24 Jul, 2024, 13:26

I try to restart terminal many times

Suiii
24 Jul, 2024, 13:27

also checking on the console web, there is no returned data here

Suiii
24 Jul, 2024, 13:37

I am trying to get the lastest code number from document , to increase it by 1

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more