forge42dev / remix-client-cache

Utility library to cache your client data in Remix.run
MIT License
157 stars 2 forks source link

Can I use this to cache client loader data too? #6

Open kiastorm opened 4 months ago

kiastorm commented 4 months ago

This is working great for server data - but in my usecase I am fetching data in the client loader that I also want to cache. Below is some rough code of what I'm trying to do - is this possible?

export async function clientLoader(args: ClientLoaderFunctionArgs) {
    const cache = await cacheClientLoader(args, {
        type: 'swr',
    })

    if (cache.whiteboards) {
        console.log(cache)
        return cache
    }

    const { serverLoader } = args
    const server = (await serverLoader()) as {}

    const whiteboards = await getAllLocalWhiteboards()

    return {
        ...server,
        whiteboards,
    }
}