swoop-inc / fast_cache

Very fast in-process cache with least-recently used (LRU) and time-to-live (TTL) expiration semantics.
MIT License
11 stars 5 forks source link

Fix bug in #shrink_if_needed. #5

Open joelnordell opened 9 years ago

joelnordell commented 9 years ago
ssimeonov commented 9 years ago

Can you provide a test that proves this is a bug?

joelnordell commented 8 years ago

Just added a test. Unfortunately, as the bug is purely internal to the FastCache::Cache class, the test has to resort to using instance_variable_get.

My other pull request, https://github.com/swoop-inc/fast_cache/pull/3, actually is what exposed the bug -- one of its tests fails without this fix.

https://github.com/ErisExchange/fast_cache/blob/eris-cleanup_procs/spec/lib/fast_cache/cache_spec.rb#L139

Failures:

  1) FastCache::Cache non-empty cache cleanup block is called when an item is removed when full
     Failure/Error: subject[:d] = 4
     NoMethodError:
       undefined method `value' for nil:NilClass
     # ./lib/fast_cache/cache.rb:217:in `shrink_if_needed'
     # ./lib/fast_cache/cache.rb:210:in `store_entry'
     # ./lib/fast_cache/cache.rb:200:in `store'
     # ./lib/fast_cache/cache.rb:81:in `[]='
     # ./spec/lib/fast_cache/cache_spec.rb:140:in `block (4 levels) in <top (required)>
joelnordell commented 8 years ago

Higher level question: would you prefer if I consolidated all three of my pull requests into one? I had originally done them all together in one branch, but split them up because they are separate concerns. However, there is a clear dependency order:

  1. RSpec fix
  2. This fix
  3. Cleanup blocks (this was my ultimate purpose for these)
ssimeonov commented 8 years ago

Separate PRs are best: you made the right decision. I merged RSpec PR. You can pick up the changes.

joelnordell commented 8 years ago

great, I'll rebase this one now so it will have a passing travis status

joelnordell commented 8 years ago

after this one is merged, I can rebase https://github.com/swoop-inc/fast_cache/pull/3 and it should be ready to merge too.

joelnordell commented 8 years ago

@ssimeonov what's the status of this -- are you going to merge it?

sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud