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

feathers-cache

v0.2.7

Published

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

Downloads

15

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 and localForage-cordovaSQLiteDriver, using cordova SQLite, IndexedDB, WebSQL or localStorage in turn when available.

Install

npm i -S feathers-cache

Usage

First, set up feathers environment both on your server and in your client codes. See the docs for detail.

Then on client-side: (in coffeescript syntax. You know how to write in JS. :) )


  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:


  # 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) => ...