开发者

What are my storage options when writing Rack middleware for Rails applications?

开发者 https://www.devze.com 2023-03-23 20:23 出处:网络
Assuming my Rack middleware is designed specifically for Rails applications, what storage options d开发者_开发问答o I have? For instance, is there a way for me to read from / write to the Rails cache?

Assuming my Rack middleware is designed specifically for Rails applications, what storage options d开发者_开发问答o I have? For instance, is there a way for me to read from / write to the Rails cache?


Yes, there is, the Rails cache is independent from Rack, you can use it like this:

Rails.cache.read("city")   # => nil
Rails.cache.write("city", "Duckburgh")
Rails.cache.read("city")   # => "Duckburgh"

You can read more about caching on Rails at the Rails caching tutorial.

You could also roll your own solution like connecting to a Redis/Memcached instance, talking to a NoSQL database. There are plenty of solutions for this issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消