# feathers-cache

> Client-side feathers services to cache data from remote services in memory or on disk.

Latest version **0.2.7** (published 2016-11-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install feathers-cache
pnpm add feathers-cache
yarn add feathers-cache
bun add feathers-cache
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.7 |
| Published | 2016-11-15 |
| First published | 2016-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | beeplin |
| Maintainers | beeplin |
| Keywords | feathers, client, cache, service |

## Links

- npm: https://www.npmjs.com/package/feathers-cache
- Repository: https://github.com/beeplin/feathers-cache
- Homepage: https://github.com/beeplin/feathers-cache#readme
- Issues: https://github.com/beeplin/feathers-cache/issues
- npm.io page: https://npm.io/package/feathers-cache

## Dependencies (5)

- [localforage](https://npm.io/package/localforage.md) ^1.4.3
- [feathers-errors](https://npm.io/package/feathers-errors.md) ^2.5.0
- [feathers-commons](https://npm.io/package/feathers-commons.md) ^0.7.8
- [feathers-query-filters](https://npm.io/package/feathers-query-filters.md) ^2.1.1
- [localforage-cordovasqlitedriver](https://npm.io/package/localforage-cordovasqlitedriver.md) ^1.5.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.2.7 (latest) — 2016-11-15
- 0.2.6 — 2016-11-12
- 0.2.5 — 2016-11-07
- 0.2.4 — 2016-11-07
- 0.2.3 — 2016-11-07
- 0.2.2 — 2016-11-07
- 0.2.1 — 2016-11-06
- 0.2.0 — 2016-11-06
- 0.1.0 — 2016-11-06
- 0.0.1 — 2016-11-05

## README

# feathers-cache

Client-side feathers services to cache data from remote services in memory or on disk. Memory cache is simply an array. Disk cache is driven by [localForage](https://github.com/localForage/localForage) and [localForage-cordovaSQLiteDriver](https://github.com/thgreasi/localForage-cordovaSQLiteDriver), using cordova SQLite, IndexedDB, WebSQL or localStorage in turn when available.

## Install

```bash
npm i -S feathers-cache
```

## Usage

First, set up `feathers` environment both on your server and in your client codes. See [the docs](https://docs.feathersjs.com/clients/feathers.html) for detail.

Then on client-side: (in coffeescript syntax. You know how to write in JS. :) )

```coffee

  cache = require 'feathers-cache'

  cachedService = app.use 'yourCachedServiceName', cache
    service: 'xxx'     # the real feathers service name it caches from
    id: 'id'           # id field name, '_id' by default
    cache:
      memory:          # get from memory first. no expiration verification since we have socke.io push.
        length: 100    # max memory cache length. 200 by default.
        find: true     # if find **only** from memory cache, ignoring real feathers. false by default.
      disk:            # if memory failed, try get from disk. fetch a timestamp to verify expiration.
        length: 500    # max disk cache length. 1000 by default.
        timestamp: xx  # timestamp field name for expiration verification. 'updatedAt' by default.
        name: 'xx'     # disk cache storage name. 'feathers-cache' by default.
        driver: [...]  # disk cache drivers. see <localforge.setDriver>. default value works ok.
      init:            # initialize this cache by find with this init query
        field: value
        $limit: xx
        $skip: xx
        $sort: ...
        $select: ...
    debug: true        # print debug info to cosole. false by default.
    methods:           # define new methods on this service besides get/find/create/...
      method1: ...
      method2: ...
      onsetup: ...     # run this when the wervice is setup (before init query is executed).
      onready: ...     # run this when the service is ready (after init query is completed).

  app.setup()          # initializate the services.

```

Now `cachedService` is a new client-side service to cache and proxy the real remote service. All caching behaviors are transparent to user, so it can be treated as the real remote service itself. In fact it can also be used as your front-end data model layer, and you can write your data processing logics into the `methods` part.

Available APIs:

```coffee

  # standard feathers service methods, proxying the real remote service's methods, with cache enabled.
  cachedService.get/find/create/update/patch/remove ...

  # your own methods defined in the 'methods' part
  cachedService.method1/method2 ...

  # a promise indicating if the service is initialized.
  cachedService.ready
  .then (data) => ...  # get initial data here

  # standard feathers service events
  cachedService.on 'created'/'updated'/'patched'/'removed', (data) => ...

  # reading/writing events: emit if there are any on-going reading/writing tasks
  cachedService.on 'reading'/'writing', (boolean) => ...

```

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