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 +4 -4
- data/.travis.yml +5 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/caches.gemspec +1 -1
- data/lib/caches/linked_list.rb +0 -1
- data/lib/caches/ttl.rb +8 -5
- data/lib/caches/version.rb +1 -1
- data/spec/caches/lru_spec.rb +1 -1
- data/spec/caches/ttl_spec.rb +17 -4
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6752525761efc14d2fdf2492d5ba51625c236d03
|
4
|
+
data.tar.gz: 89c4640117c1b2a534872f8e843e886d8e1b118d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f5cede570a244ae57eabefa1e4a77c1dd650480dfd7aa016755412d839ed0117d8ae634e2fc1c4eab2e34956a655d01e9bc6daf536f55680c479ecbb5172a2e
|
7
|
+
data.tar.gz: f4b5db03b6f1c5bdc0022426a5c19f2c5f4ddf23722f5daa8d99fcf82b1167044e87b8437d1221c8acc2828e9a19f5e1ecad1933d994c9dca701c22599739616
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -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.
|
data/caches.gemspec
CHANGED
@@ -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", "~>
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
24
24
|
|
25
25
|
spec.add_development_dependency "benchmark-ips", "~> 2.0"
|
26
26
|
end
|
data/lib/caches/linked_list.rb
CHANGED
data/lib/caches/ttl.rb
CHANGED
@@ -26,8 +26,11 @@ module Caches
|
|
26
26
|
end
|
27
27
|
if current?(key)
|
28
28
|
record_cache_hit
|
29
|
-
data
|
30
|
-
|
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
|
-
(
|
88
|
+
expiration_time(key) >= current_time
|
86
89
|
end
|
87
90
|
|
88
|
-
def
|
89
|
-
|
91
|
+
def expiration_time(key)
|
92
|
+
data.fetch(key).fetch(:time) + ttl
|
90
93
|
end
|
91
94
|
|
92
95
|
def full?
|
data/lib/caches/version.rb
CHANGED
data/spec/caches/lru_spec.rb
CHANGED
data/spec/caches/ttl_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative '../../lib/caches/ttl'
|
|
4
4
|
|
5
5
|
describe Caches::TTL do
|
6
6
|
|
7
|
-
let(:ttl) { 0.
|
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{
|
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(:
|
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.
|
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.
|
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-
|
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: '
|
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: '
|
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.
|
121
|
+
rubygems_version: 2.4.5
|
121
122
|
signing_key:
|
122
123
|
specification_version: 4
|
123
124
|
summary: Caches with hash-like access
|