caches 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 443cc1eff19b292441d504e849ba7cfe09931f03
4
- data.tar.gz: 18ab2f338cada16695d69e18452f223c276c7050
3
+ metadata.gz: 6752525761efc14d2fdf2492d5ba51625c236d03
4
+ data.tar.gz: 89c4640117c1b2a534872f8e843e886d8e1b118d
5
5
  SHA512:
6
- metadata.gz: 7902d5bb624352d4c0122d247f09ba28dfe41ca68f3041bccc83f7035799102299b2c084d7a2a5bb98071358febc3bff51c7b59516182d6bcb89c55e738c5191
7
- data.tar.gz: 38f8cdec9b5e46634c2cdd9b4124a6f17c70171813fcecc56e1c2242961b359d27bb47273c0a3edb6f4c4a5e3cfc0ebda9d4f4e2c7a7a89547ea24abc5ad61f8
6
+ metadata.gz: 2f5cede570a244ae57eabefa1e4a77c1dd650480dfd7aa016755412d839ed0117d8ae634e2fc1c4eab2e34956a655d01e9bc6daf536f55680c479ecbb5172a2e
7
+ data.tar.gz: f4b5db03b6f1c5bdc0022426a5c19f2c5f4ddf23722f5daa8d99fcf82b1167044e87b8437d1221c8acc2828e9a19f5e1ecad1933d994c9dca701c22599739616
@@ -0,0 +1,5 @@
1
+ # Maybe look at advanced settings like those used in https://github.com/lostisland/faraday/blob/master/.travis.yml
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ - 2.1.0
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
 
6
6
  - Nothing
7
7
 
8
+ ## 0.0.8 - 2015-08-14
9
+
10
+ - Bugfix: in TTL, "refresh on read" also puts key last in line for eviction in case the cache gets too full
11
+
8
12
  ## 0.0.7 - 2015-03-09
9
13
 
10
14
  - `#clear` method clears a cache's data and stats
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  `caches` is a Ruby gem, providing a small collection of caches with good performance and hash-like access patterns. Each is named for its cache expiration strategy - when it will drop a key.
4
4
 
5
+ [![Build Status](https://travis-ci.org/nathanl/caches.svg?branch=master)](https://travis-ci.org/nathanl/caches)
6
+
5
7
  ## Usage
6
8
 
7
9
  `caches` provides the following classes.
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", "~> 2.14"
23
+ spec.add_development_dependency "rspec", "~> 3.3"
24
24
 
25
25
  spec.add_development_dependency "benchmark-ips", "~> 2.0"
26
26
  end
@@ -74,7 +74,6 @@ module Caches
74
74
  length == 0
75
75
  end
76
76
 
77
- # TODO - move these to a module and use in caches, too
78
77
  alias :blank? :empty?
79
78
  def present?
80
79
  !empty?
@@ -26,8 +26,11 @@ module Caches
26
26
  end
27
27
  if current?(key)
28
28
  record_cache_hit
29
- data[key][:value].tap {
30
- data[key][:time] = current_time if refresh
29
+ data.fetch(key).fetch(:value).tap {
30
+ if refresh
31
+ data[key][:time] = current_time
32
+ nodes.move_to_head(data[key][:node])
33
+ end
31
34
  }
32
35
  else
33
36
  record_cache_miss
@@ -82,11 +85,11 @@ module Caches
82
85
  end
83
86
 
84
87
  def current?(key)
85
- (current_time - data[key][:time]) < ttl
88
+ expiration_time(key) >= current_time
86
89
  end
87
90
 
88
- def expired?(key)
89
- !current?(key)
91
+ def expiration_time(key)
92
+ data.fetch(key).fetch(:time) + ttl
90
93
  end
91
94
 
92
95
  def full?
@@ -1,3 +1,3 @@
1
1
  module Caches
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -53,7 +53,7 @@ describe Caches::LRU do
53
53
  describe "memoize" do
54
54
 
55
55
  it "requires a block" do
56
- expect{cache_memoize(:c)}.to raise_error
56
+ expect{cache.memoize(:c)}.to raise_error(ArgumentError)
57
57
  end
58
58
 
59
59
  let(:greeting) { 'hi' }
@@ -4,7 +4,7 @@ require_relative '../../lib/caches/ttl'
4
4
 
5
5
  describe Caches::TTL do
6
6
 
7
- let(:ttl) { 0.01 }
7
+ let(:ttl) { 0.1 }
8
8
  let(:most_of_ttl) { ttl * 0.8 }
9
9
  let(:options) { { ttl: ttl} }
10
10
  let!(:cache) {
@@ -107,7 +107,7 @@ describe Caches::TTL do
107
107
  describe "memoize" do
108
108
 
109
109
  it "requires a block" do
110
- expect{cache_memoize(:c)}.to raise_error
110
+ expect{cache.memoize(:c)}.to raise_error(ArgumentError)
111
111
  end
112
112
 
113
113
  let(:greeting) { 'hi' }
@@ -177,7 +177,8 @@ describe Caches::TTL do
177
177
 
178
178
  describe "supporting a maximum size" do
179
179
 
180
- let(:options) { {ttl: ttl, max_keys: 3} }
180
+ let(:refresh) { false }
181
+ let(:options) { {ttl: ttl, max_keys: 3, refresh: refresh} }
181
182
 
182
183
  let!(:cache) {
183
184
  described_class.new(options).tap {|c|
@@ -205,7 +206,19 @@ describe Caches::TTL do
205
206
 
206
207
  it "evicts the oldest key on insertion" do
207
208
  cache[:d] = 'Drinian'
208
- expect(cache.size).to eq(3)
209
+ expect(cache.keys).to eq([:b, :c, :d])
210
+ end
211
+
212
+ context "if it was set to refresh on read" do
213
+
214
+ let(:refresh) { true }
215
+
216
+ it "takes reads into account when deciding what to evict" do
217
+ cache[:a]
218
+ cache[:d] = 'Drinian'
219
+ expect(cache.keys).to eq([:a, :c, :d])
220
+ end
221
+
209
222
  end
210
223
 
211
224
  it "doesn't evict on update" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caches
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Long
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.14'
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.14'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: benchmark-ips
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - ".travis.yml"
78
79
  - CHANGELOG.md
79
80
  - CONTRIBUTING.md
80
81
  - Gemfile
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.2.2
121
+ rubygems_version: 2.4.5
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Caches with hash-like access