LRUCache(T)
A simple LRU Cache to store items of whatever type T
Constants
Log = ::Log.for(self)
VERSION = "1.0.5"
Constructors
Creates a new LRUCache with the given max_size and clean_interval
Instance methods
Deletes a item from the LRU Cache.
expire_time argument is in seconds.
cache = LRUCache(String).new(5)
cache.set("key", "value", 5)
cache.del("key")
pp cache.get("key") # => nil
Gets the item associated with the key
cache = LRUCache(String).new(5)
cache.set("key", "value", 5)
pp cache.get("key") # => "value"
items
Gets all the items that the LRU cache is holding.
cache = LRUCache(String).new(5)
cache.set("key", "value", 5)
cache.set("key2", "value2")
pp cache.items # => {"key" => LRUCache::Item(String)(@expires_at=1771043818, @value="value"), "key2" => LRUCache::Item(String)(@expires_at=nil, @value="value2")}
on_event
Define a callback for when a new event is received.
cache = LRUCache(String).new(5)
cache.on_event do |e|
puts e.key
puts e.event_type
end
Sets a item of the desired Type T into the LRU Cache.
expire_time argument is in seconds.
cache = LRUCache(String).new(5)
cache.set("key", "value", 5)
pp cache.get("key") # => "value"
size
Gets the current amount of items the LRU cache is holding.
cache = LRUCache(String).new(5)
cache.set("key", "value", 5)
cache.set("key2", "value2")
pp cache.size # => 2