Skip to content

sa-0001/lru-cache-cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lru-cache

A simple LRU (least-recently-used) which allows you to define the max. number of items in the hash, or the max size of the items in the hash (by bytesize of the string key and value). When a new cache item is added, and the items/bytes are exceeded, the cache item which was least recently used (by either get or set) is deleted.

Installation

Add this to your application's shard.yml:

dependencies:
  lru-cache:
    github: sa-0001/lru-cache-cr

Usage & Examples

require "lru-cache"

# limit to X items
cache = LRUCache.new max_items: 10

# limit of X bytes
cache = LRUCache.new max_bytes: 1e9

# key is a String, and val is any class which implements method #bytesize
cache.set "key", %({"a":"b","c":"d"})

# check if key exists
cache.has? "key"

# returns nil if key not found
val = cache.get "key"

# raises exception if key not found
val = cache.get! "key"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published