简体   繁体   English

我应该使用什么来托管一个公共 JSON 文件,该文件很少在不重新部署我的整个 web 应用程序的情况下更改?

[英]What should I use to host a public JSON file that rarely changes without redeploying my whole webapp?

I've a react app hosted on firebase and a realtime database for user data.我有一个托管在 firebase 上的反应应用程序和一个用于用户数据的实时数据库。

Currently, there's a json file in my app's code containing reference data.目前,我的应用程序代码中有一个 json 文件,其中包含参考数据。 This file might change once every few months.此文件可能每隔几个月更改一次。

Where could I host this file so that I could update it without redeploying the whole webapp?我可以在哪里托管这个文件,这样我就可以在不重新部署整个 web 应用程序的情况下更新它?

I thought about using Firebase Storage, but it seems inefficient to download the file on every render.我考虑过使用 Firebase 存储,但在每次渲染时下载文件似乎效率低下。 Is there a way to only download it once and cache it for a certain amount of time?有没有办法只下载一次并缓存一段时间?

thank you谢谢你

yes, you can fetch it the first time and store it in localStorate , and about the expiration time, add a key as a specific expiration time, and when time over re-fetch it again, eg (for three month later):是的,您可以第一次获取它并将其存储在localStorate中,关于到期时间,添加一个密钥作为特定的到期时间,当时间超过时重新获取它,例如(三个月后):

const date = new Date();
date.setMonth(date.getMonth() + 3);
const expirationTime = date.getTime();

{
   data: {...some data},
   expirationTime
}

and each time you have to check the expirationTime if the current time was bigger than expirationTime you have to re-fetch the data.并且每次您必须检查expirationTime如果当前时间大于expirationTime您必须重新获取数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应如何使用php mysql或json文件检索数据? - what should i use php mysql or json file to retrieve data? 如果我想从 json 文件与 Z67166080962DE308CD762A 一起读取配对对象,我应该使用什么 java class? - What java class should I use for pair objects if I want to read them in from a json file with gson? 我的 json api fetch 似乎不起作用,我应该对数据使用什么? - My json api fetch seems not to work, what should I use with data? 我应该从解码的JSON创建新的较小数组还是按原样使用整个JSON数组? - Should I create new smaller array from decoded JSON or use the whole JSON array as is? 没有登录就无法呈现json。 我该怎么办? - cannot render json without login. What should i do? 当我有HTTPException时,我的JSON响应应包含什么? - What should my JSON response contain when I have an HTTPException? 我应该使用什么来序列化和传递json数据? - What should I be using to serialize and pass my json data? 我应该在SQL Server中为json列的默认值使用什么? - What should I use for a default value for a json column in SQL Server? 经典ASP和JSON:我应该使用哪种解析器/序列化器? - Classic ASP and JSON: What parser/serializer should I use? 我应该使用什么来转换特定的json格式 - What i should use to convert specific json format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM