简体   繁体   English

如何在Heroku的Rails中保存少量数据

[英]How to Save A Tiny Bit Of Data In Rails On Heroku

I have a super simple Ruby on Rails app that doesn't have any ActiveRecord code. 我有一个超级简单的Ruby on Rails应用,没有任何ActiveRecord代码。 The app saves literally one line of text via a "record" URL. 该应用程序实际上通过“记录” URL保存一行文本。 I want to be able to then hit a URL that feeds back whatever line of text was recorded. 然后,我希望能够找到一个URL,该URL反馈记录的任何文本行。 Like this: 像这样:

Person 1: POST to www.myUrl.heroku.com/recorder, DATA = "A really interesting string" 第1个人:POST到www.myUrl.heroku.com/recorder,DATA =“一个非常有趣的字符串”

Person 2: GET to www.myUrl.heroku.com/recorder, I want my response to contain "A really interesting string" 人2:获取www.myUrl.heroku.com/recorder,我希望我的回复包含“一个非常有趣的字符串”

This sounds SUPER SIMPLE which is why I am mega-frustrated that I can't do it. 这听起来超级简单,这就是为什么我为无法做到而感到沮丧。 Heroku has an ephemeral file system - I read all about that. Heroku有一个临时文件系统-我读了所有有关它的内容。 And Heroku logs can't be accessed from within the app (as far as I can tell) - I can use command line tools but that doesn't help. Heroku日志无法从应用程序内访问(据我所知)-我可以使用命令行工具,但这无济于事。 But I only need the data there for 10 minutes! 但是我只需要那里的数据10分钟!

Here are the things we tried so far: 这是到目前为止我们尝试过的事情:

  • Save to a local file in /tmp - this works sometimes but fails when Heroku flushes the directory in between HTTP requests, which is expected behavior 保存到/ tmp中的本地文件-有时可以工作,但是当Heroku在HTTP请求之间刷新目录时会失败,这是预期的行为
  • Save to log file in /log via direct file write - same as above, works sometimes but also gets flushed often 通过直接文件写入保存到/ log中的日志文件-与上述相同,有时可以正常工作,但也经常刷新
  • Use a Ruby logger to write to a new log file - ditto 使用Ruby记录器写入新的日志文件-同上
  • Use puts to write to the Heroku log - nice idea, but Heroku doesn't let you write to the production log this way, it writes somewhere else that you can access through command line but (as far as I can tell) not within the app 使用puts写入Heroku日志-一个好主意,但是Heroku不允许您以这种方式写入生产日志,而是将其写入可以通过命令行访问的其他位置,但是(据我所知)不在应用

I really don't want to sign up for AWS since this is a service for someone else, and it seems ridiculous to sign up for 1 tb of data transfer for literally 1 line of text (it overwrites anytime someone "records"). 我真的不想注册AWS,因为这是为其他人提供的服务,并且为1行文本注册1 TB的数据传输似乎很可笑(在有人“记录”时,它会被覆盖)。 I also would prefer not to create a whole ActiveRecord deal given, again, literally 1 line of text. 我也不想再给定字面上的1行文本来创建整个ActiveRecord处理。

Any ideas here? 这里有什么想法吗? Is there some micro cache or whatever I can use? 是否有一些微缓存或我可以使用的任何缓存? I only need the data to persist for about 10 minutes. 我只需要将数据保留大约10分钟即可。

Thanks! 谢谢!

Damien 达米安

PS Using Ruby 2.0, rails 3.something. PS使用Ruby 2.0,rails 3.something。

您可以利用Rails应用程序缓存-rails.cache.write('key','value')和rails.cache.read('key')

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM