Project

hashcache

0.0
No commit activity in last 3 years
No release in over 3 years
hashcache
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Introducing the hashcache gem

require 'hashcache'

hc = HashCache.new(size:5)
hc.read('fun') {'apple'}
hc.read('run') {'banana'}
hc.read('dun') {'grapes'}
hc.read('tun') {'pear'}
hc.read('sun') {'pineapple'}
hc.read('dun') {'grapes'}
hc.read('dun') {'grapes'}
hc.read('fun') {'apple'}
hc.read('wun') {'cherries'}

hc
#=> #<HashCache:0x97db1f4 @size=5, @h={"tun"=>"pear", "sun"=>"pineapple", "dun"=>"grapes", "fun"=>"apple", "wun"=>"cherries"}>

Only the 5 most recent items will be stored in the hash, and the block is only used if the item is being added to the hash.