persistent-cache 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +1 -3
- data/lib/persistent-cache/version.rb +1 -1
- data/persistent-cache.gemspec +3 -3
- data/spec/storage/storage_sqlite_spec.rb +85 -41
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68dd568fb3b97d162664532ee06caf46f2a0f065
|
4
|
+
data.tar.gz: 7fbfeda53e86fc9fa842720b70e12dd141071d47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94eb9ead4f1199fea92d7d6adf6097f55ad6b6f5672aaf7c94600cd4a0c63d892999de42c8443b0591c7d5a6fe67ee0f715be1ff603250e1e6fb335e1592b6b8
|
7
|
+
data.tar.gz: 0714b953628f1c326d59ac070f85f9a56dd08fc65fe32228fd28ead66d022dca2eb84cf41f30b6cf58f4907ecea99fb0ad863a9f69bcb630e93b6a22af671711
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -113,9 +113,7 @@ If you'd like persistent cache to rather store keys using an encoding of your pr
|
|
113
113
|
|
114
114
|
Please send feedback and comments to the authors at:
|
115
115
|
|
116
|
-
Ernst van Graan <ernst.van.graan@
|
117
|
-
|
118
|
-
Wynand van Dyk <wynand.van.dyk@hetzner.co.za>
|
116
|
+
Ernst van Graan <ernst.van.graan@gmail.com>
|
119
117
|
|
120
118
|
1. Fork it
|
121
119
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
data/persistent-cache.gemspec
CHANGED
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'persistent-cache/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.authors = ["Ernst van Graan"
|
8
|
-
gem.email = ["ernst.van.graan@
|
7
|
+
gem.authors = ["Ernst van Graan"]
|
8
|
+
gem.email = ["ernst.van.graan@gmail.com"]
|
9
9
|
gem.description = %q{Persistent Cache using a pluggable back-end (e.g. SQLite)}
|
10
10
|
gem.summary = %q{Persistent Cache has a default freshness threshold of 179 days after which entries are no longer returned}
|
11
|
-
gem.homepage = ""
|
11
|
+
gem.homepage = "https://github.com/evangraan/persistent-cache.git"
|
12
12
|
|
13
13
|
gem.files = `git ls-files`.split($\)
|
14
14
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -67,55 +67,90 @@ describe Persistent::StorageSQLite do
|
|
67
67
|
|
68
68
|
context "when asked to store a key value pair" do
|
69
69
|
it "should store the key/value pair in the db, with the current time as timestamp" do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
70
|
+
attempts = 0
|
71
|
+
begin
|
72
|
+
start_time = Time.now - 1
|
73
|
+
@iut.save_key_value_pair(@test_key, @test_value)
|
74
|
+
handle = SQLite3::Database.open(@db_name)
|
75
|
+
result = handle.execute "select value, timestamp from #{Persistent::StorageSQLite::DB_TABLE} where key=?", serialize(@test_key)
|
76
|
+
expect(result.nil?).to eq(false)
|
77
|
+
expect(result[0].nil?).to eq(false)
|
78
|
+
expect(result[0][0]).to eq(serialize(@test_value))
|
79
|
+
test_time = Time.parse(result[0][1])
|
80
|
+
expect(test_time).to be > start_time
|
81
|
+
expect(test_time).to be < start_time + 600
|
82
|
+
rescue SQLite3::IOException
|
83
|
+
attempts = attempts + 1
|
84
|
+
raise if attempts > 3
|
85
|
+
retry
|
86
|
+
end
|
80
87
|
end
|
81
88
|
|
82
89
|
it "should store the key/value pair in the db, with a timestamp specified" do
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
attempte = 0
|
91
|
+
begin
|
92
|
+
test_time = (Time.now - 2500)
|
93
|
+
@iut.save_key_value_pair(@test_key, @test_value, test_time)
|
94
|
+
handle = SQLite3::Database.open(@db_name)
|
95
|
+
result = handle.execute "select value, timestamp from #{Persistent::StorageSQLite::DB_TABLE} where key=?", serialize(@test_key)
|
96
|
+
expect(result.nil?).to eq(false)
|
97
|
+
expect(result[0].nil?).to eq(false)
|
98
|
+
expect(result[0][0]).to eq(serialize(@test_value))
|
99
|
+
time_retrieved = Time.parse(result[0][1])
|
100
|
+
expect(time_retrieved.to_s).to eq(test_time.to_s)
|
101
|
+
rescue SQLite3::IOException
|
102
|
+
attempts = attempts + 1
|
103
|
+
raise if attempts > 3
|
104
|
+
retry
|
105
|
+
end
|
92
106
|
end
|
93
107
|
|
94
108
|
it "should overwrite the existing key/value pair if they already exist" do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
109
|
+
attempts = 0
|
110
|
+
begin
|
111
|
+
@iut.save_key_value_pair(@test_key, @test_value)
|
112
|
+
@iut.save_key_value_pair(@test_key, "testvalue2")
|
113
|
+
handle = SQLite3::Database.open(@db_name)
|
114
|
+
result = handle.execute "select value from #{Persistent::StorageSQLite::DB_TABLE} where key=?", serialize(@test_key)
|
115
|
+
expect(result.nil?).to eq(false)
|
116
|
+
expect(result[0].nil?).to eq(false)
|
117
|
+
expect(result.size).to eq(1)
|
118
|
+
expect(result[0][0]).to eq(serialize("testvalue2"))
|
119
|
+
rescue SQLite3::IOException
|
120
|
+
attempts = attempts + 1
|
121
|
+
raise if attempts > 3
|
122
|
+
retry
|
123
|
+
end
|
103
124
|
end
|
104
125
|
end
|
105
126
|
|
106
127
|
context "When looking up a value given its key" do
|
107
128
|
it "should retrieve the value from the database" do
|
108
|
-
|
109
|
-
|
110
|
-
|
129
|
+
attempts = 0
|
130
|
+
begin
|
131
|
+
@iut.save_key_value_pair(@test_key, @test_value)
|
132
|
+
result = @iut.lookup_key(@test_key)
|
133
|
+
expect(result[0]).to eq(@test_value)
|
134
|
+
rescue SQLite3::IOException
|
135
|
+
attempts = attempts + 1
|
136
|
+
raise if attempts > 3
|
137
|
+
retry
|
138
|
+
end
|
111
139
|
end
|
112
140
|
|
113
141
|
it "should retrieve the timestamp when the value was stored from the database" do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
142
|
+
attempts = 0
|
143
|
+
begin
|
144
|
+
now = Time.now.to_s
|
145
|
+
@iut.save_key_value_pair(@test_key, @test_value)
|
146
|
+
sleep 1
|
147
|
+
result = @iut.lookup_key(@test_key)
|
148
|
+
expect(result[1]).to eq(now)
|
149
|
+
rescue SQLite3::IOException
|
150
|
+
attempts = attempts + 1
|
151
|
+
raise if attempts > 3
|
152
|
+
retry
|
153
|
+
end
|
119
154
|
end
|
120
155
|
|
121
156
|
it "should return an empty array if a key is not in the database" do
|
@@ -131,12 +166,19 @@ describe Persistent::StorageSQLite do
|
|
131
166
|
end
|
132
167
|
|
133
168
|
it "should delete the entry if it is present" do
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
169
|
+
attempts = 0
|
170
|
+
begin
|
171
|
+
@iut.save_key_value_pair(@test_key, @test_value)
|
172
|
+
result = @iut.lookup_key(@test_key)
|
173
|
+
expect(result[0]).to eq(@test_value)
|
174
|
+
@iut.delete_entry(@test_key)
|
175
|
+
result = @iut.lookup_key(@test_key)
|
176
|
+
expect(result).to eq(nil)
|
177
|
+
rescue SQLite3::IOException
|
178
|
+
attempts = attempts + 1
|
179
|
+
raise if attempts > 3
|
180
|
+
retry
|
181
|
+
end
|
140
182
|
end
|
141
183
|
end
|
142
184
|
|
@@ -192,6 +234,8 @@ describe Persistent::StorageSQLite do
|
|
192
234
|
iut.save_key_value_pair("one", "one")
|
193
235
|
iut.save_key_value_pair("two", "two")
|
194
236
|
iut.save_key_value_pair("three", "three")
|
237
|
+
rescue SQLite3::IOException
|
238
|
+
retry
|
195
239
|
end
|
196
240
|
|
197
241
|
def delete_database
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persistent-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernst van Graan
|
8
|
-
- Wynand van Dyk
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2016-
|
11
|
+
date: 2016-07-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
@@ -139,8 +138,7 @@ dependencies:
|
|
139
138
|
version: '0'
|
140
139
|
description: Persistent Cache using a pluggable back-end (e.g. SQLite)
|
141
140
|
email:
|
142
|
-
- ernst.van.graan@
|
143
|
-
- wvd@hetzner.co.za
|
141
|
+
- ernst.van.graan@gmail.com
|
144
142
|
executables: []
|
145
143
|
extensions: []
|
146
144
|
extra_rdoc_files: []
|
@@ -161,7 +159,7 @@ files:
|
|
161
159
|
- spec/storage/storage_directory_spec.rb
|
162
160
|
- spec/storage/storage_ram_spec.rb
|
163
161
|
- spec/storage/storage_sqlite_spec.rb
|
164
|
-
homepage:
|
162
|
+
homepage: https://github.com/evangraan/persistent-cache.git
|
165
163
|
licenses: []
|
166
164
|
metadata: {}
|
167
165
|
post_install_message:
|