The project is in a healthy, maintained state
Basic least-recently-used cache implementation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Foobara::LruCache

A basic least-recently-used cache implementation

Installation

Typical stuff: add gem "foobara-lru-cache to your Gemfile or .gemspec file. Or even just gem install foobara-lru-cache if just playing with it directly in scripts.

Usage

The usage is cache.cached(key) { value_to_cache_when_no_cache_hit }

An example:

require "foobara/lru_cache"

cache = Foobara::LruCache.new

criteria = { name: "Fumiko" }

# This will actually run FindCapybara
record = cache.cached(criteria) do
  FindCapybara.run!(criteria)
end

puts record.name

# This will not run FindCapybara and will instead return the cached record
record = cache.cached(criteria) do
  FindCapybara.run!(criteria)
end

puts record.name

The default capacity is 10 but you can override this with LruCache.new(100) if you wanted a capacity of 100.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/foobara/lru-cache

License

This project is dual licensed under your choice of the Apache-2.0 license and the MIT license. Please see LICENSE.txt for more info.