Neat! Pickled Muskrat!

    read-cached-file

    1.0.7 • Public • Published

    readCachedFile

    Cache the result of a usually slow and/or resource/time consuming operation (e.g. response from a server request, heavy computation) into a local file.

    📖 Example

    import readCachedFile from 'read-cached-file'
    
    // Callback to retrieve the data
    const getPhotoData = async () => await (await fetch('https://jsonplaceholder.typicode.com/photos')).text()
    
    // Run script once: calls getPhotoData and creates photos-data.json
    // Run a second time: no network request, reads from photos-data.json
    const data = await readCachedFile("./photos-data.json", getPhotoData)
    
    // Do something with the data
    const photos = JSON.parse(data)

    💡 Tips

    • To force retrieving/re-generating the data, set forceUpdate to true:
    data = await readCachedFile("./photos-data.json", getPhotoData, true)

    Install

    npm i read-cached-file

    DownloadsWeekly Downloads

    9

    Version

    1.0.7

    License

    MIT

    Unpacked Size

    6.38 kB

    Total Files

    8

    Last publish

    Collaborators

    • kevduc