Rails缓存:它是什么以及如何使用它

时间:2022-08-17 16:53:49

I have an app I am building that has a user fill out a form and stores the information in various files until the end where it uploads the data, one file at a time, to a single source.

我有一个我正在构建的应用程序,用户填写表单并将信息存储在各种文件中,直到它将数据(一次一个文件)上传到单个源的结尾。

I was wondering if this is the same idea as caching, or if I should be using some sort of built in rails cache to do this instead.

我想知道这是否与缓存相同,或者我是否应该使用某种内置的rails缓存来代替。

And if so, what is the difference between a cache and what I am doing (storing data temporarily in files I create)?

如果是这样,缓存和我正在做什么之间有什么区别(暂时将数据存储在我创建的文件中)?

Are there any really good articles I could read that would help me understand caching and the various benefits of caching? That is.. if it is more than what I assume a cache to be (just reserved temporary memory)..

是否有任何我能阅读的非常好的文章可以帮助我理解缓存和缓存的各种好处?那是..如果它超过我假设的缓存(只是保留临时内存)..

1 个解决方案

#1


1  

I am assuming that your user form consists of different stages? Instead of writing to files which is a slow process, you should consider saving them in temporary variables or cookies in browser(which will have added benefit of allowing resuming of form from where user left off).

我假设您的用户表单包含不同的阶段?您应该考虑将它们保存在临时变量或浏览器中的cookie中,而不是写入缓慢进程的文件(这将增加允许从用户停止的地方恢复表单的好处)。

By Rails cache, you mean server side caching. i.e. you store something which is repetitive and not likely to change. Examples include static contact us pages, headers of pages etc. Wherever you feel that something is done multiple times without any changes in the end result, you can cache it away.

通过Rails缓存,您的意思是服务器端缓存。即你存储的东西是重复的,不太可能改变。示例包括静态联系我们页面,页面标题等。无论您认为某些内容多次完成而没有对最终结果进行任何更改,您都可以将其缓存。

As you can see, it is not exactly relevant to your scenario. Consider the session storage if the form is not abnormally long.

如您所见,它与您的方案并不完全相关。如果表单不是异常长,请考虑会话存储。

Note: Do a fair bit of reading on cache expiry and strategies before you get into that. Caches if done lightly can raise some very-hard-to-track bugs.

注意:在开始之前,请先了解缓存过期和策略。如果轻松完成缓存可能会引发一些非常难以跟踪的错误。

#1


1  

I am assuming that your user form consists of different stages? Instead of writing to files which is a slow process, you should consider saving them in temporary variables or cookies in browser(which will have added benefit of allowing resuming of form from where user left off).

我假设您的用户表单包含不同的阶段?您应该考虑将它们保存在临时变量或浏览器中的cookie中,而不是写入缓慢进程的文件(这将增加允许从用户停止的地方恢复表单的好处)。

By Rails cache, you mean server side caching. i.e. you store something which is repetitive and not likely to change. Examples include static contact us pages, headers of pages etc. Wherever you feel that something is done multiple times without any changes in the end result, you can cache it away.

通过Rails缓存,您的意思是服务器端缓存。即你存储的东西是重复的,不太可能改变。示例包括静态联系我们页面,页面标题等。无论您认为某些内容多次完成而没有对最终结果进行任何更改,您都可以将其缓存。

As you can see, it is not exactly relevant to your scenario. Consider the session storage if the form is not abnormally long.

如您所见,它与您的方案并不完全相关。如果表单不是异常长,请考虑会话存储。

Note: Do a fair bit of reading on cache expiry and strategies before you get into that. Caches if done lightly can raise some very-hard-to-track bugs.

注意:在开始之前,请先了解缓存过期和策略。如果轻松完成缓存可能会引发一些非常难以跟踪的错误。