# express-cache-tags

> A (not yet) fully featured cache-tagging solution for node servers.

Latest version **1.0.0** (published 2019-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-cache-tags
pnpm add express-cache-tags
yarn add express-cache-tags
bun add express-cache-tags
```

## 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.0 |
| Published | 2019-02-27 |
| First published | 2019-02-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 431.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lucas Constantino Silva |
| Maintainers | lucasconstantino |

## Links

- npm: https://www.npmjs.com/package/express-cache-tags
- npm.io page: https://npm.io/package/express-cache-tags

## Dependencies (5)

- [express](https://npm.io/package/express.md) ^4.16.4
- [figures](https://npm.io/package/figures.md) ^2.0.0
- [signale](https://npm.io/package/signale.md) ^1.3.0
- [on-finished](https://npm.io/package/on-finished.md) ^2.3.0
- [memory-cache](https://npm.io/package/memory-cache.md) ^0.2.0

## Recent versions

- 1.0.0 (latest) — 2019-02-27

## README

# express-cache-tags

[![npm version](https://img.shields.io/npm/v/express-cache-tags.svg?style=flat-square)](https://www.npmjs.com/package/express-cache-tags)
[![Downloads/week](https://img.shields.io/npm/dw/express-cache-tags.svg)](https://npmjs.org/package/express-cache-tags)
[![License](https://img.shields.io/npm/l/express-cache-tags.svg)](https://github.com/lucasconstantino/express-cache-tags/blob/master/package.json)
[![build status](https://img.shields.io/travis/lucasconstantino/express-cache-tags/master.svg?style=flat-square)](https://travis-ci.org/lucasconstantino/express-cache-tags)
[![coverage](https://img.shields.io/codecov/c/github/lucasconstantino/express-cache-tags.svg?style=flat-square)](https://codecov.io/github/lucasconstantino/express-cache-tags)

**A _(not yet)_ fully featured cache-tagging solution for node servers.**

---

## Motivation

Most HTTP servers rely on third-party systems for caching (such as CDNs). Even though this is probably the right approach, sometimes we need a fully featured, local, and simple caching and puring solution for a varying number of reasons. Whatever the reason is for you, we got you covered!

## Usage

### Installation

```
npm i express-cache-tags
```

### Usage

#### Middleware

```js
import express from 'express'
import cache from 'express-cache-tags'

express()
  .use(cache())
  // .get(...) your server routes
  .listen(3000)
```

#### Options

All the usage options receive the same options object:

| prop              | description                             | default                                                                  |
| ----------------- | --------------------------------------- | ------------------------------------------------------------------------ |
| cacheFactory      | A [cache-object](#cache-object) factory | A new [`memory-cache`](https://github.com/ptarjan/node-cache) instace    |
| generateKey       | A cache-key generator                   | `(req) => \`${req.method}:${rq.url}\``                                   |
| shouldCache       | Predicate to decide caching             | `() => true // cache anything the middleware touches`                    |
| statusHeader      | Hitting status header name              | `'CDN-Cache'`                                                            |
| logger            | Logging specific options                |                                                                          |
| logger.enabled    | Wheter or not to log operations         | `true`                                                                   |
| logger.scope      | Logging scope (see `signale`)           | `'CACHE'`                                                                |
| cacheTags         | Cache-tags specific options             |                                                                          |
| cacheTags.extract | Request cache-tags extractor            | `(req, res) => (res.get('Cache-Tags') || '').split(',').filter(Boolean)` |
| purger            | Purging specific options                |                                                                          |
| purger.extract    | Purging tags extractor                  | `(req, res) => (req.query.invalidate || '').split(',').filter(Boolean)`  |

##### Cache-object

A [`memory-cache`](https://github.com/ptarjan/node-cache) compatible object, with at least `get`, `put`, `keys`, and `clear` methods.

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