项目作者: victorkt

项目描述 :
Caching module for solr-client
高级语言: JavaScript
项目地址: git://github.com/victorkt/solr-client-cache.git
创建时间: 2016-11-20T22:44:10Z
项目社区:https://github.com/victorkt/solr-client-cache

开源协议:MIT License

下载


solr-client-cache

Caching module for solr-client using cacheman.

Installation

This module is distributed using npm which comes bundled with node:

  1. npm install --save solr-client-cache

Usage

  1. const solr = require('solr-client');
  2. const solrCache = require('solr-client-cache');
  3. const client = solr.createClient();
  4. solrCache(client, {
  5. ttl: 60,
  6. engine: 'redis',
  7. host: '127.0.0.1',
  8. port: 6379
  9. });
  10. // search Solr with cache
  11. client
  12. .cache()
  13. .search(query, (err, results) => { /* ... */ });
  14. // search Solr without cache
  15. client
  16. .search(query, (err, results) => { /* ... */ });

If you want a different TTL (Time to Live) for a specific query, then pass it to the cache() function.

  1. const solr = require('solr-client');
  2. const solrCache = require('solr-client-cache');
  3. const client = solr.createClient();
  4. solrCache(client, { ttl: 60 });
  5. // search Solr with cache
  6. client
  7. .cache(10) // 10 seconds TTL instead of 60s
  8. .search(query, (err, results) => { /* ... */ });

All cache options (TTL, engine, etc…) are described on cacheman README.

Test

Just run:

  1. npm test

License

MIT