cache-manager-memcached-store

memcached impl for cache-manager

Usage no npm install needed!

<script type="module">
  import cacheManagerMemcachedStore from 'https://cdn.skypack.dev/cache-manager-memcached-store';
</script>

README

Node Cache Manager store for Memcached

js-standard-style Build Status npm version

The Memcached store for the node-cache-manager

Module can use different compatible memcache clients as the underlying memcache library:

Installation

Install one of the memcached clients from above and cache-manager-memcached-store

npm i memcache-pp --save
npm i cache-manager-memcached-store --save

Acknowledgements

Some of the project scaffolding and test/comments are lifted from node-cache-manager-redis

Till version 3.0.0 cache-manager-memcached-store uses memcache-plus as the underlying memcached library. Newer versions allow to choose any compatible library by passing it's constructor in a driver option. See example below.

Usage examples

const Memcache = require('memcache-pp')
const cacheManager = require('cache-manager')
const memcachedStore = require('cache-manager-memcached-store')

const memcachedCache = cacheManager.caching({
    store: memcachedStore,
    driver: Memcache,
    // http://memcache-plus.com/initialization.html - see options
    options: {
        hosts: ['127.0.0.1:11211']
    } 
})

const ttl = 30

// Compression must be manually set - see memcached-plus documentation
// The key must always be a string
// http://memcache-plus.com/set.html
memcachedCache.set('foo', 'bar', ttl, function(err) {
  if (err) {
    throw err
  }
    
  // http://memcache-plus.com/get.html
  memcachedCache.get('foo', function(err, result) {
      console.log(result)
      // >> 'bar'
      memcachedCache.del('foo', function(err) {})
  })
})