Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
运行 ruby 脚本时,是否可以让对象在多次调用后保留在内存中?
ruby run.rb
在 OSX 中工作。
查看Marshal图书馆。
Marshal.dump允许您序列化对象中的数据并将其保存到文件中。
Marshal.dump
下次您的程序启动时,您可以检查该文件是否存在并用于Marshal.load获取该数据并重新创建您的对象。
Marshal.load
您可以为此使用缓存,例如 memcached 与dalli或 redis 与各种redis 客户端。