项目作者: patrixr

项目描述 :
An opinionated memcache
高级语言: JavaScript
项目地址: git://github.com/patrixr/tronicache.git
创建时间: 2019-10-24T02:18:01Z
项目社区:https://github.com/patrixr/tronicache

开源协议:MIT License

下载


Tronicache

forthebadge

An argument-aware opinionated memcache

Installation

  1. npm install --save tronicache

Usage

Create a cached service

Indefinite caching by default

  1. const { cached } = require('tronicache');
  2. const service = cached({
  3. getUser(uid) {
  4. // cached indefinitely
  5. }
  6. })

Configurable timeout

  1. const { cached } = require('tronicache');
  2. const service = cached({
  3. timeout: 2 * 60 * 6000, // all methods at the root are cached for 2 minutes
  4. getUser(uid) {
  5. // cached for 2 minutes
  6. }
  7. })

Nested namespace support

  1. const { cached } = require('tronicache');
  2. const service = cached({
  3. users: {
  4. getUser(uid) {
  5. // cached indefinitely
  6. },
  7. posts: {
  8. // all methods within 'posts' will be cached for 2 minutes
  9. timeout: 2 * 60 * 1000,
  10. postsOfUser(uid) {
  11. const user = this.users.getUser(uid); // notice the scope
  12. // ...
  13. }
  14. }
  15. },
  16. notifications: {
  17. // nothing under 'notifications' is cached
  18. cache: false,
  19. fetch() {
  20. // ...
  21. },
  22. archive: {
  23. cache: true, // override in the subnamespace
  24. fetch() { }
  25. }
  26. }
  27. });