有什么方法可以使用 Apollo-server 2.x 实现服务器端缓存吗?

Is there any way to implement server-side caching using Apollo-server 2.x?

Currently I am using "GrandStack" for my application . The challenge I am facing with cache .I want to maintain Cache at both side Client and Back-end.

在客户端:

我正在使用 React Js,Apollo-client:默认情况下,Apollo-client 在应用程序级别维护一个商店(使用 Apollo 提供的客户端包装整个应用程序)

Que here .. If I navigate to any visited page that data should server from cache even on page refresh

在后端: 我正在使用 Apollo-server 2 + express + Neo4j 作为 DB

Is there any way to cache "client request" at server ? If user hit same request to server that data should comes from server cache ?

请帮我提供一些参考代码。提前致谢。

对于相同的场景,我实现了 LRU 缓存,其中我将查询存储为键,将响应存储为值。

const LRU = require("lru-cache")

const lruCache = new LRU({
    maxElements: 1000,
    length: (n, key) => {
        return n * 2 + key.length
    },
    dispose: function (key, n) {
        // n.close()
    },
    maxAge: 1000 * 60 * 60
})

设置值 lruCache.set(key, value) 并获取 const data = lruCache.get(key);

"key"是您的要求。

还有其他选择,但这是最受欢迎的(我相信)

URL - https://www.npmjs.com/package/lru-cache