SamSaffron / lru_redux

An efficient optionally thread safe LRU Cache
MIT License
285 stars 20 forks source link

Ruby 2.1+ Performance Improvement, Threadsafe Cache Refactor and New Cache Methods #7

Closed Seberius closed 9 years ago

Seberius commented 9 years ago

Hello,

@Seberius also I have given push access to you for this repo just in case you need it. (we should still do PRs for these bigger changes though)

Thanks!

As discussed in #3 , this is a general improvement branch to ease the implementation of a TTL cache.

First some notes about 1.8 support.

Now on to the branch features

Ruby 2.1+ Performance Improvement

Ruby 2.1 appears to have resolved the performance issue reported in https://bugs.ruby-lang.org/issues/8312. We can get some significant improvement by using #shift in Ruby 2.1+. Please refer to the changes made to README.md for benchmark results (both ran on the same machine).

Threadsafe Cache Refactor

The ThreadSafeCache implementation has been refactored as mixin, namely LruRedux::Util::SafeSync. The mixin will be compatible with the TTL cache, which cuts down on maintenance overhead.

New Cache Methods

A new cache method #key? and its alias #has_key? have been added. This is method is equivalent to Hash#key? and is common in other cache implementations (e.g. clojure.core.cache). This method was also added to a LruRedux fork by @AlexSc, but never pull requested back.

A new alias of #delete called #evict has been added. This is equivalent to the #evict method proposed in #3 and is common in other cache implementations (e.g. clojure.core.cache).

Tests have been updated to cover the new method.

Typos in changelog

FIxed a couple typos in the changelog.

Tests

This branch is currently passing all tests on 1.8.7-p375, 2.0.0-p643, 2.2.0, jruby-1.7.19 and jruby-9.0.0.0-pre1.

Fabulous run in 0.003189s, 7212.2923 runs/s, 21009.7209 assertions/s.

23 runs, 67 assertions, 0 failures, 0 errors, 0 skips
SamSaffron commented 9 years ago

So sorry about those typos

Regarding 1.8, I agree, we should do a version bump and simply remove all 1.8 behaviour from the repo, people needing 1.8 can use the old gem.

Nice to see the shift fix is in, that code sure was crusty.