Skip to content

Conversation

@jsumners
Copy link
Member

This PR switches out the requirement for Catbox style caches with a requirement for abstract-cache style caches. This allows greater flexibility due to the fact that abstract-cache allows re-using established connections. So, for example, the user could register multiple instances of fastify-caching for different routes while using the same connection:

const redis = require('ioredis')({host: '127.0.0.1'})
const abcache = require('abstract-cache')({
  driver: {
    name: 'abstract-cache-redis',
    options: {client: redis}
  }
})

const fastify = require('fastify')()
const fastifyCaching = require('fastify-caching')

fastify.register((instance, opts, next) => {
  instance.register(fastifyCaching, {
    segment: 'foo',
    cache: abcache
  })

  instance.get('/foo', async function (req, reply) {
    await this.cache.set('foo', 'foo', 1000) // goes to the 'foo' Redis collection
    return {foo: 'foo'}
  })

  next()
})

fastify.register((instance, opts, next) => {
  instance.register(fastifyCaching, {
    segment: 'bar',
    cache: abcache
  })

  instance.get('/bar', async function (req, reply) {
    await this.cache.set('bar', 'bar', 1000) // goes to the 'bar' Redis collection
    return {bar: 'bar'}
  })

  next()
})

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@allevo allevo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jsumners jsumners merged commit c84733a into master Nov 25, 2017
@jsumners jsumners deleted the abstract-cache branch November 25, 2017 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants