Ruby/Cache 0.3

What is Ruby/Cache

Ruby/Cache is a library for caching objects based on the LRU algorithm for Ruby. The official page is <URL:>.

How to install

  1. $ ruby install.rb config
  2. $ ruby install.rb setup
  3. $ ruby install.rb install

How to use

Here is a simple usage:

require 'cache'

cache =
cache['foo'] = 'bar'
p cache['foo']
p cache['foo']



This is a more complicated example:

# Set the maximum number of cached objects and the expiration time to
# 100 and 60 (secs), respectively.
cache =, nil, 100, 60)
puts 'I will generate a prime number greater than any given number!'
while true
  puts 'Input an integer: '
  i = gets.to_i
  puts cache.fetch(i) { generate_prime_greater_than(i) }


You may redistribute it and/or modify it under the same term as Ruby's.


Yoshinori K. Okuji <>