Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timed_lru

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timed_lru

  • 0.5.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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"]

FAQs

Package last updated on 06 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc