Exploring Ruby by exploring caches
Find a file
2026-06-25 18:24:04 -04:00
.config/rubocop Initial commit 2026-06-21 14:50:48 -04:00
bin Initial commit 2026-06-21 14:50:48 -04:00
lib Initial commit 2026-06-21 14:50:48 -04:00
spec Initial commit 2026-06-21 14:50:48 -04:00
.rspec Initial commit 2026-06-21 14:50:48 -04:00
Gemfile Initial commit 2026-06-21 14:50:48 -04:00
Gemfile.lock Initial commit 2026-06-21 14:50:48 -04:00
LICENCE.txt Add licence 2026-06-25 18:24:04 -04:00
mise.toml Initial commit 2026-06-21 14:50:48 -04:00
README.md Initial commit 2026-06-21 14:50:48 -04:00

Exploring Ruby Through Caching

This project serves as an example of various classic caching algorithms in Ruby, and was written as part of an ongoing project to learn the language.

Running

The executable c will hit the selected caching algorithm with a number of requests, with cache keys distributed according to the selected distribution:

bundle exec bin/c -n {num_requests} -d {distribution} -a {algorithm} -s
{cache_size} -f {field_size}

Cache keys can be any number within 0...field_size. The field size, along with the number of requests and distribution affect the likelihood of a request being hittable. The size of the cache and its algorithm affect the efficacy of the cache in any given situation.

Available distributions:

  • uniform: Keys are picked from the available range completely at random
  • gauss:μ:σ: Keys are picked by a Gaussian (normal) distribution. Select a mean and standard deviation that make sense for your chosen field size. A mean of field_size / 2 and a standard deviation of around field_size / 4 is a good place to start.