Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loopback-cache

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loopback-cache

Cache solutions for Loopback

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by9.09%
Maintainers
3
Weekly downloads
 
Created
Source

loopback-cache

Build Status Coverage Status

Cache solutions for Loopback.

How to use

Install

npm install loopback-cache --save

Config

To load the mixins.

# model-config.json
{
  "_meta": {
    ...
    "mixins": [
      ...
      "loopback-cache/mixins",
      ...
    ]
  },
  ...
}

To use the redis backend, setup a model using the redis connector or the ioredis connector and use the mixin CacheModel with the model. The TTL is in seconds, see http://redis.io/commands/expire.

# The model JSON
{
  ...
  "mixins": {
    "CacheModel": {
      "backend": "redis",
      "ttl": 3600
    }
  },
  ...
}

To use the couchbase backend, setup a model using the couchbase3 connector and use the mixin CacheModel with the model. The TTL is in seconds, for value larger than 30 * 24 * 60 * 60 seconds (30 days), it would be converted to absolute times (from the epoch) in seconds, see http://docs.couchbase.com/sdk-api/couchbase-node-client-2.1.2/Bucket.html#touch.

# The model JSON
{
  ...
  "mixins": {
    "CacheModel": {
      "backend": "couchbase",
      "ttl": 3600
    }
  },
  ...
}

Extending

Note: This module doesn't do anything on the DB or table level. For example MongoDB would require a special index that matches the field, which should be prepared before you start the application.

To add the support for a specific connector (it's a model mixin so we are talking connectors not DB directly), extend this module in a place that will be executed (for example boot).

var loopbackCache = require('loopback-cache');

And add a new backend (you can also override backends). See https://github.com/Wiredcraft/loopback-cache/tree/master/backends for examples.

loopbackCache.backends.something = function(Model, options) {};

Now you can use it in the model JSON, same as any other backend.

{
  "mixins": {
    "CacheModel": {
      "backend": "something",
      "ttl": 3600
    }
  }
}

Contributing

If you want to add a new backend to the module, just drop the file in the backends directory, and send us a PR.

Git Summary

 project  : loopback-cache
 repo age : 11 months
 active   : 16 days
 commits  : 46
 files    : 18
 authors  :
    22  CCharlieLi   47.8%
    22  Makara Wang  47.8%
     2  fraserxu     4.3%

Keywords

FAQs

Package last updated on 27 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc