Memmo is a small library for creating key-based, in-memory caches in Ruby.
It features thread safety and TTLs.
require "memmo"
$memmo = Memmo.new
$memmo.register(:popular_posts, ttl: 60) do
# Somewhat expensive query
Post.find(...)
end
# This call will trigger a miss and will run our expensive query.
$memmo[:popular_posts].each do |post|
puts(post)
end
# This call will be fast for the next 60 seconds.
$memmo[:popular_posts]
It's common to avoid caches when testing your application. For this purpose you can disable Memmo entirely:
require "test/unit"
Memmo.enabled = false
See UNLICENSE
. With love, from Educabilia.