# read-file-and-cache

> Reads a file and caches the result (in memory). If the file was modified, will return updated version of it (options available)

Latest version **1.0.2** (published 2016-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install read-file-and-cache
pnpm add read-file-and-cache
yarn add read-file-and-cache
bun add read-file-and-cache
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-01-13 |
| First published | 2016-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nikita Gavrilov |
| Maintainers | ilearnio |
| Keywords | read, file, cache, update, readFileAndCache, fs, readFile |

## Links

- npm: https://www.npmjs.com/package/read-file-and-cache
- Repository: https://github.com/ilearnio/read-file-and-cache
- Issues: https://github.com/ilearnio/read-file-and-cache/issues
- npm.io page: https://npm.io/package/read-file-and-cache

## Dependencies (1)

- [es6-promise](https://npm.io/package/es6-promise.md) ^3.0.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2016-01-13
- 1.0.0 — 2016-01-12
- 0.0.1 — 2016-01-12

## README

# read-file-and-cache
[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]

Reads a file and caches the result (in memory). If the file was modified, will return updated version of it (options available)

## Use cases

* Imagine, you have an .html layout, which your server outputs to the client
on every request. You don't want to read the file every time but still want to
check, once in a while, whether it was changed, so then you can respond with the
new version of it.
* Same layout, but now you need to respond always with a cached version of it
when you're in production environment. But when in development, you want to
respond always with the fresh version of the file

## Install

```
$ npm install --save read-file-and-cache
```

## Usage

```js
const readFileAndCache = require('read-file-and-cache')

//
// using a callback
//
readFileAndCache(filepath, function(err, result) {
  // ...
})

//
// or a Promise
//
readFileAndCache(filepath).then(function(result) {
  // ...
})

//
// or syncronously
//
const readFileAndCacheSync = require('read-file-and-cache').sync
// ES6: import { readFileAndCacheSync } from 'read-file-and-cache'

let result = readFileAndCacheSync(filepath)

//
// Give it some options
//
let result = readFileAndCache(filepath, {
  // Read synchronously (default: false)
  sync: true,
  // If true, cache for a file will be never updated (default: false)
  never_update: process.env.NODE_ENV === 'production', // never update cache when in production
  // Delay between checks for file modifications in sec. (default: 0)
  check_delay: 3600 // check for updates every hour (0 to check everytime)
})
```

[npm-image]: https://img.shields.io/npm/v/read-file-and-cache.svg
[npm-url]: https://npmjs.org/package/read-file-and-cache
[travis-image]: https://img.shields.io/travis/ilearnio/read-file-and-cache/master.svg
[travis-url]: https://travis-ci.org/ilearnio/read-file-and-cache

---
_Source: https://npm.io/package/read-file-and-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
