如何使阿波罗缓存无效?

时间:2018-06-26 10:26:50

标签: caching graphql apollo

有人知道如何在apollo中执行缓存失效吗?

我在解析器中设置缓存提示:

export default (root, args, { userId }, { cacheControl }) => {
  cacheControl.setCacheHint({ maxAge: 60 });

  return userId && Meteor.users.findOne(userId);
};

但是,如果发生了某些变化并且maxAge足够大,那么更改将不会得到体现。

我现在正在考虑以突变形式调用cacheControl.setCacheHint({ maxAge: 0 }),还有其他方法吗?

1 个答案:

答案 0 :(得分:0)

您可以检查以下内容:https://github.com/lucasconstantino/apollo-cache-invalidation#readme

您可以使用功能匹配

const randomKeyMatch = key => Math.random() >= 0.5

const update = invalidateFields(() => [
  [randomKeyMatch, 'happy']
])

client.mutate({ mutation, update })
相关问题