Code Monkey home page Code Monkey logo

Comments (2)

jmikrut avatar jmikrut commented on September 2, 2024

To me this points to a huge complexity in the way that NextJS just simply extends fetch with its own caching in the first place.

This is a very good question. I guess the answer here depends on where and how you want to cache database calls. Caching is a massive topic, and there are lots of ways to go about it depending on the platform that you leverage.

For example, if you're just running Payload on an Express server normally, you might not want to cache Payload API responses directly. But, other times, you might definitely want to cache and in turn logically cache-bust as documents are updated. In Payload Cloud, we are building a way to do this on Cloudflare that will run totally behind the scenes (cache GET responses, and cache-bust when updates happen).

As far as I understood it they payload client methods are directly using the mongodb api without fetch in-between correct?

This is correct. The Payload client talks directly to the database, no fetch involved.

So maybe it would be nice to add a getPayload payload function to next-payload package which is using getPayload from payload package but wraps every cacheable function (like find/findMany) in a cache function?

This depends largely on what you want to see happen and would only be useful in a subset of applications. For example, in this demo package, the [slug]/page.tsx that you referenced above statically renders its content, so no caching to Payload is really necessary.

If you wanted to dynamically render certain pages, to me, that would imply that you would not want to render pages statically in the first place, so you should not be caching anything at all anyway.

But, if you did want to dynamically render pages with some dynamic content but other content from Payload cached, then that's where I think the react-cache approach would come in. And that would be application-specific.

Does that make sense?

from next-payload-demo.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.