Yes, there is ActiveSupport::Cache::Store
Abstract cache storage class. There are several cache repositories that have their own additional features. See classes in the ActiveSupport :: Cache module, for example. ActiveSupport :: Cache :: MemCacheStore. MemCacheStore is currently the most popular cache drive for large production sites.
Some implementations may not support all methods that go beyond the basic cache methods of extraction, writing, reading, existence? and deletion.
ActiveSupport :: Cache :: Store can store any Ruby serializable object.
http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
cache = ActiveSupport::Cache::MemoryStore.new cache.read('Chicago') # => nil cache.write('Chicago', 2707000) cache.read('Chicago') # => 2707000
As for the expiration time, this can be done by passing the time as an initialization parameter
cache = ActiveSupport::Cache::MemoryStore.new(expires_in: 5.minutes)
If you want to cache a value with a different expiration time, you can also set this when writing the value to the cache
cache.write(key, value, expires_in: 1.minute)
source share