DanielHreben/sequelize-transparent-cache

View on GitHub
packages/sequelize-transparent-cache-memcache-plus/src/memcache-plus-adaptor.js

Summary

Maintainability
A
0 mins
Test Coverage
class MemcachePlusAdaptor {
  constructor ({ client, namespace, lifetime = 0 }) {
    this.client = client
    this.namespace = namespace
    this.lifetime = lifetime
  }

  _withNamespace (key) {
    const namespace = this.namespace
    const keyWithNamespace = namespace
      ? [namespace, ...key]
      : key

    return keyWithNamespace.join(':')
  }

  set (key, value) {
    return this.client.set(
      this._withNamespace(key),
      value,
      this.lifetime
    )
  }

  get (key) {
    return this.client.get(this._withNamespace(key))
  }

  del (key) {
    return this.client.delete(this._withNamespace(key))
  }
}

module.exports = MemcachePlusAdaptor