How to cache / serialize a Net :: IMAP object in Ruby / Rails?

I am creating an IMAP web client in Rails and want to cache an IMAP object between requests. I planned to serialize the object and save it in Redis (since it only caches strings), however, none of the popular serialization methods seem to work.

Marshall and ActiveSupport :: Cache :: MemoryStore both result in the following error:

Marshal.dump(imap)
TypeError: no marshal_dump is defined for class Mutex

YAML serialization works, but deserialization fails.

s = YAML::dump(imap) # works, i.e. loads up a string with the imap data
imap2 = YAML::load(s)
TypeError: allocator undefined for Thread

Is there another alternative caching mechanism that works for any ruby ​​objects, especially those that can use streams inside? Does the alternative keystore (I used Redis) support such caching? Even better, is there Rails for remembering certain objects, and not for deserializing them?

PS > Ruby 1.9.2 Rails 3.0.3 Macbook, .

+3
1

( ). , , ( tcp 5 ). IMAP, , . - , . , ? , , IMAP .

+1

Source: https://habr.com/ru/post/1785770/


All Articles