Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Assuming my Rack middleware is designed specifically for Rails applications, what storage options do I have? For instance, is there a way for me to read from / write to the Rails cache?

like image 564
Kevin Pang Avatar asked Dec 12 '25 15:12

Kevin Pang


1 Answers

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.

like image 153
Maurício Linhares Avatar answered Dec 14 '25 07:12

Maurício Linhares