首页 > 解决方案 > 更新/补丁无法在使用在钩子中使用的 feathers-redis-cache 的 feathersjs 应用程序服务中工作

问题描述

我正在使用 feathers-redis-cache 来缓存我的 feathersjs 应用程序中某些服务的数据。这就是我的钩子的样子:

const {hooks: redisCache} = require('feathers-redis-cache');
///... some code ..///
before: {
    all: [],
    find: [validateSearchParams,redisCache.before()],
    get: [redisCache.before()],
    create: [throw400Error('Not supported')],
    update: [throw400Error('Not supported')],
    patch:  [preventAnyUnallowedChanges, redisCache.before()],
    remove: [throw400Error('Not supported')]
  },

  after: {
    all: [],
    find: [removeSensitiveData(), redisCache.after({ expiration: 600 })],
    get: [preventUnallowedConfig, removeSensitiveData(), redisCache.after({expiration: 600 })],
    create: [redisCache.purge()],
    update: [redisCache.purge()],
    patch: [preventUnallowedData, redisCache.purge()],
    remove: [redisCache.purge()]
  },

现在,前端正在发送通过 GET 调用(feathersjs get)获取的格式正确的数据,并且在更改并保存表单中的数据之后,PATCH(feathersjs 补丁)正在返回旧的缓存数据。一旦我从之前的钩子/补丁方法 redisCache.before() 中删除,数据的修补就没有问题了。使用该 redis 方法并使用 find 而不是 get 获取数据,这个问题就不存在了。

如果使用 get 获取数据然后修补并且使用 find 获取数据时它正在工作,有人可以解释为什么修补不起作用的原因吗?

标签: javascriptnode.jsredisfeathersjsfeathers-redis-cache

解决方案


推荐阅读