npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-cache-file

v1.0.0

Published

Express middleware to cache static files in server memory

Downloads

24

Readme

express-cache-file

Express middleware to cache static files in server memory.

npm Package Version

This is a simple package without external dependencies. (e.g. it doesn't require redis)

Features

  • express middleware
  • cache files in memory
  • customizable cache policy
  • customizable cache size

Installation

You can install this package with npm, pnpm, yarn or slnpm

npm install express-cache-file

Usage Example

import cacheFile from 'express-cache-file'
import express from 'express'

let app = express()

app.use(
  cacheFile('public', {
    cacheSize: '50mb',
    update: {
      expire: '5 seconds',
      mode: 'cache_first',
    },
  }),
)

app.listen(8100, () => {
  console.log('listening on http://localhost:8100')
})

Typescript Signature

export function cacheFile(
  root: string,
  options?: CacheFileOptions,
): (req, res, next) => void

export default cacheFile

export type CacheFileOptions = {
  readMode?: ReadMode
  update?: false | UpdateOptions
  cacheSize?: CacheSize
  redirect?: boolean // redirect '/' to 'index.html', default true
}

export type UpdateOptions = {
  expire?: UpdateInterval
  mode?: UpdateMode
}

export type UpdateMode =
  | 'cache_first' // default
  | 'wait'

export type ReadMode =
  | undefined
  | 'async' // default
  | 'sync'

export type UpdateInterval =
  | undefined
  | false // equivalent to to 'never'
  | 'never' // default
  | 'immediate'
  | number // ms, zero is equivalent to 'immediate'
  | string // duration format, e.g. '5 minutes'

export type CacheSize =
  | undefined
  | 'unlimited' // default
  | number // bytes
  | string // size format, e.g. '5mb'

Duration Format

Format: [value][unit]

| Unit Prefix | Meaning | | ----------: | :---------- | | ms | millisecond | | s | second | | m | minute | | h | hour | | d | day |

Remarks:

  • The unit is case-insensitive.
  • The space between value and unit is optional.
  • When the unit is not specified, the value is treated as second if smaller than 1000, otherwise treated as ms.

Examples:

  • 10ms
  • 5 seconds

Size Format

Format: [value][unit]

| Unit Prefix | Meaning | | ----------: | :---------- | | B | byte | | | | | KiB | 1024^1 byte | | MiB | 1024^2 byte | | GiB | 1024^3 byte | | TiB | 1024^4 byte | | PiB | 1024^5 byte | | | | | KB | 1000^1 byte | | MB | 1000^2 byte | | GB | 1000^3 byte | | TB | 1000^4 byte | | PB | 1000^5 byte |

Remarks:

  • The unit is case-insensitive.
  • The space between value and unit is optional.
  • When the unit is not specified, the value is treated as MB if smaller than 1000, otherwise treated as byte.

License

This is a Free and Open Source Software (FOSS) licensed under BSD-2-Clause