An efficient optionally thread safe LRU Cache
An efficient, thread safe LRU cache.
Add this line to your application's Gemfile:
gem 'lru_redux'And then execute:
$ bundleOr install it yourself as:
$ gem install lru_reduxRuby 1.8 - v0.8.4 is the last compatible release:
gem 'lru_redux', '~> 0.8.4'…The TTL cache extends the functionality of the LRU cache with a Time To Live eviction strategy. TTL eviction occurs on every access and takes precedence over LRU eviction, meaning a 'live' value will never be evicted over an expired one.
…#getset Takes a key and block. Will return a value if cached, otherwise will execute the block and cache the resulting value.#fetch Takes a key and optional block. Will return a value if cached, otherwise will execute the block and return the resulting value or return nil if no block is provided.#[] Takes a key. Will return a value if cached, otherwise nil.#[]= Takes a key and value. Will cache the value under the key.#delete Takes a key. Will return the deleted value, otherwise nil.#evict Alias for #delete.#clear Clears the cache. Returns nil.#each Takes a block. Executes the block on each key-value pair in LRU order (most recent first).#to_a Return an array of key-value pairs (arrays) in LRU order (most recent first).#key? Takes a key. Returns true if the key is cached, otherwise false.#has_key? Alias for #key?.#count Return the current number of items stored in the cache.#max_size Returns the current maximum size of the cache.#max_size= Takes a positive number. Changes the current max_size and triggers a resize. Also triggers TTL eviction on the TTL cache.#ttl Returns the current TTL of the cache.#ttl= Takes :none or a positive number. Changes the current ttl and triggers a TTL eviction.#expire Triggers a TTL eviction.see: benchmark directory (a million random lookup / store)
…Implementation is slightly different for Ruby versions before 2.1 due to a Ruby bug. http://bugs.ruby-lang.org/issues/8312
……This is a list of the caches that are used in the benchmarks.
git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)No open issues yet, or sync has not completed.