Skip to content

okdistribute/fs-cache-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fs-cache-middleware

A streaming cache for any filesystem

npm install fs-cache-middleware

Similar to express-asset-file-cache-middleware, but doesn't require express and supports streaming payloads.

Usage

const fileCacheMiddleware = require('fs-cache-middleware')

function getAsset (url, params) {
  return {
    contentType: 'image/png',
    contentLength, // if known
    stream: streamingFetch('https://get/that/asset.png')
  }
}

var cache = fileCacheMiddleware(getAsset, { 
  maxSize: 10 * 1024 * 1024 * 1024 
  cacheDir: '/tmp'
})

http.createServer(funcrion (req, res) {
  // Pass extra parameters on the fly with the request
  var params = { token: 'my-token' }
  cache(req, res, params, (err) => {
    if (err) {
      logger.error(err)
      res.statusCode = 500
      res.end(err.message)
    }
  })
}

About

A streaming cache for any filesystem

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published