volatile_hash 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ volatile_hash
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ default
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- volatile_hash (0.0.1)
4
+ volatile_hash (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README CHANGED
@@ -33,3 +33,5 @@ rake
33
33
  Based on a gist by github.com user joshaven at https://gist.github.com/184837
34
34
 
35
35
  Some input from github user supertaz, considerable help on the TTL-based version.
36
+ Idea for the LRU cache developed at TrueCar Inc.
37
+
data/lib/volatile_hash.rb CHANGED
@@ -15,7 +15,7 @@ class VolatileHash
15
15
  def [](key)
16
16
  value = @cache[key]
17
17
  if @strategy == 'ttl'
18
- if expired?(key)
18
+ if @registry[key] && expired?(key)
19
19
  @cache.delete key
20
20
  @registry.delete key
21
21
  value = nil
@@ -29,6 +29,15 @@ describe VolatileHash do
29
29
  @cache[:x].should be_nil
30
30
  end
31
31
 
32
+ it "should continue returning nil for cached values after the TTL expires" do
33
+ @cache[:x].should == @x.to_s
34
+
35
+ sleep(0.8)
36
+
37
+ @cache[:x].should be_nil
38
+ @cache[:x].should be_nil
39
+ end
40
+
32
41
  it "should not throw out least-recently used value" do
33
42
  @cache[:y] = 1
34
43
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'volatile_hash'
3
- s.version = '0.0.2'
3
+ s.version = '0.0.3'
4
4
  s.date = '2012-02-22'
5
5
  s.summary = "Implements LRU and TTL caches"
6
6
  s.description = "Implements key-based cache that can have a least-recently-used or time-to-live expiration strategy"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volatile_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -66,7 +66,8 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
- - .rvmrc
69
+ - .ruby-gemset
70
+ - .ruby-version
70
71
  - Gemfile
71
72
  - Gemfile.lock
72
73
  - LICENSE
data/.rvmrc DELETED
@@ -1,2 +0,0 @@
1
- rvm use ruby-1.9.2-p180@volatile_hash --create
2
-