Loopback:存储来自远程方法的对象,以便以后在服务器中重用

Loopback: Store object from remote method for later reuse within the Server

所以我正在研究远程方法,我正在考虑一个逻辑挑战:

当调用远程方法时,我不想每次都重新查询数据库,而是希望存储返回给远程方法调用者的响应对象。

只要数据库中的数据不变,远程调用的响应总是相同的,因此不需要数据库调用。

Does there exist way to store such a variable (that can contain a considerable amount of data), so that it would be available for a different remote method and/or a later call of the same method?

server/boot/storage.js

module.exports = (server) => {
    server.variable = 'thing I want to store';
}

server/boot/storage-methods.js

module.exports = (server) => {
    server.models.Model1.accessGlobalStorage= async () => {return server.variable};
    server.models.Model2.accessGlobalStorage= async () => {return server.variable};
    // Insert remote method definition here
}

Do I think in a strange direction?

不,这是很多事情背后的想法,比如 redis,这是一种更传统、更可扩展的方式来做你正在做的事情。

Would it be better to manage such issues on the client and reduce the REST API calls (Which I also try to keep at a minimum)?

http://wiki.c2.com/?PrematureOptimization

程序员浪费大量时间思考或担心程序非关键部分的速度