Project

timed_lru

0.0
Low commit activity in last 3 years
No release in over a year
Thread-safe LRU implementation with (optional) TTL and constant time operations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Timed LRU

Build Status Dependency Status

My implementation of a simple, thread-safe LRU with (optional) TTLs and constant time operations. There are many LRUs for Ruby available but I was unable to find one that matches all three requirements.

Install

Install it via gem:

gem install timed_lru

Or just bundle it with your project.

Usage Example

# Initialize with a max size (default: 100) and a TTL (default: none)
lru = TimedLRU.new max_size: 3, ttl: 5

# Add values
lru["a"] = "value 1"
lru["b"] = "value 2"
lru["c"] = "value 3"
lru.keys # => ["a", "b"]

# Wait a second
sleep(1)

# Add more values
lru["d"] = "value 4"
lru.keys # => ["b", "c", "d"]

# Sleep a little longer
sleep(4)
lru["c"] # => "value 3"
lru.keys # => ["c", "d"]