- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从一个非常慢且很少更改的 API 中获取数据,因此我想我会使用内存缓存。我首先尝试了一种非常简单的方法,将其保存到我的路由中加载程序函数范围之外的变量中:
let cache;
export const loader = async () => {
if (!cache) {
// we always end up here
cache = await (await fetch("...)).json()
}
}
但这没有用。然后我尝试了一个合适的缓存库 (lru-cache
),但那个缓存也总是空的。然后我意识到每个请求都会重新加载整个文件,我猜这是开发模式的事情,所以我尝试将缓存的创建移动到一个单独的文件 cache.server.ts 并将其导入那里。
import LRU from "lru-cache";
console.log("Creating cache"); // this is logged on each request
const cache = new LRU({ max: 200 });
export default cache;
但该文件似乎也会在每次请求时重新加载。
如果我构建了一个生产版本并运行它,一切都很好,但如果有某种方法让它也能在开发模式下工作,那就太好了。
最佳答案
Remix 清除了 require
缓存开发中的每个请求以支持 <LiveReload/>
.为了确保您的缓存在这些清除后仍然存在,您需要将其分配给 global
对象。
这是笑话教程中的一个例子
import { PrismaClient } from "@prisma/client";
let db: PrismaClient;
declare global {
var __db: PrismaClient | undefined;
}
// this is needed because in development we don't want to restart
// the server with every change, but we want to make sure we don't
// create a new connection to the DB with every change either.
if (process.env.NODE_ENV === "production") {
db = new PrismaClient();
} else {
if (!global.__db) {
global.__db = new PrismaClient();
}
db = global.__db;
}
export { db };
https://remix.run/docs/en/v1/tutorials/jokes#connect-to-the-database
关于javascript - 如何在 Remix.run 开发模式下使用内存缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72661999/
/~/@ReMix-Run/Router/dist/router.cjs.js模块分析失败:/HOME/sharib/Desktop/Full Stack Developer Tutorial/MER
我想知道是否有一种方法可以重定向路由或返回带有数据的 Response 并使用 loader 函数在另一个页面获取它。 基本上我正在尝试创建一个带有表单的新对象并重定向到另一个我想显示创建成功消息的页
我尝试使用 Remix 将合约部署到测试网(所有测试网都返回相同的消息),但出现此错误: Gas estimation errored with the following message (see
当我点击 remix.ethereum.org 下的创建时,我不明白智能合约的实际去向。例如,如果我选择 Injected Web3,这应该会将合约发布到 ropsten 测试网上,对吧?但是我怎样才
我是 Solidity 新手,这是我正在测试和重新混合的代码 browser/Untitled.sol:1:1: : 源文件未指定所需的编译器版本!考虑添加“pragma Solidity ^0.4.
默认情况下,Remix.run运行时似乎使用3000端口进行本地开发: ❯ npm run dev > dev > concurrently "npm run dev:css" "remix dev"
我需要从一个非常慢且很少更改的 API 中获取数据,因此我想我会使用内存缓存。我首先尝试了一种非常简单的方法,将其保存到我的路由中加载程序函数范围之外的变量中: let cache; export c
我需要从一个非常慢且很少更改的 API 中获取数据,因此我想我会使用内存缓存。我首先尝试了一种非常简单的方法,将其保存到我的路由中加载程序函数范围之外的变量中: let cache; export c
大家好,我是皮汤。周五翻 Github 趋势榜看到了 Remix 这个内容,觉得挺有发展前景的,初步了解了一下具体的特性,分享给大家。 近期,由 React Router 原班团队打造,基
我想不出一种方法将空字节传递给 remix 上的 solidity 函数。这是我的功能 function checkEmptyBytes(bytes calldata _data) exter
我有这个错误“类型错误:返回参数类型地址不能隐式转换为预期类型(第一个返回变量的类型)应付地址。--> Driven.sol:233:16: | 233 | return msg.sender; |
我在 Remix OS 中保存和退出 vi 编辑器时遇到问题。我在 Remix 中更改了/system/etc/init.sh 中的一些配置。此外,当我想通过单击 (Esc) 保存并退出时,然后是 :
我遵循了以下示例:https://github.com/mui-org/material-ui/tree/master/examples/remix-with-typescript在 Remix 上使
我在 remix run 中派发我的 action 时遇到了一些麻烦 - 我有一个 Aside,其中包含我购物车中的所有数据 - 我有一个表格可以整理所有数据 - 以及我想要结帐的时间待创建我想调用该
这可能是我遗漏的一个简单错误,但我终究无法弄清楚如何在此契约(Contract)中设置 msg.value 变量。我在网上看到这个值是与交易关联的wei的数量,但是我作为合约的调用者具体怎么设置这个值
我阅读了关于 Action 的 Remix 文档,我可以找到的关于 Action 的大部分信息是它使用带有按钮提交的表单 POST 来触发 Action export default function
我正在研究基于 solidity 的智能合约,但遇到了一个问题。每次我尝试创建这个合约时,我的论点都没有得到证实。 我希望在选择名称时出现“OreOreCoin”,但我得到的却是一个空字符串。 和 这
我对 Remix.run 很感兴趣,但有一件事我真的不明白。在框架的技术解释中,它说: While Remix runs on the server, it is not actually a ser
我已经在 Remix IDE 中编译了 openzeppelin-contracts 代码。同时,我收到以下警告。 Warning: The "extcodehash" instruction is
想在不安装深度操作系统的情况下获得最新的深度桌面体验吗?UbuntuDDE Remix 21.10 终于登场了! 深度 20.3 已经发布了一段时间,做了一些基本的改进和细微的视觉变化。 但
我是一名优秀的程序员,十分优秀!