persistent-cache 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWY0N2Y0ZmU4YmE3ZDRhMTAwNDg4MmU2YmUyNDE1ZjZhZDgzZWJlNQ==
5
+ data.tar.gz: !binary |-
6
+ NjZiMjdhYWYyYWM4ZjY1YmFiOWJkNThhOTUzNjdjZjE1NTcxNWI3MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YWRhODc0MGYwNjNjOGI3ZTg0NTEwMmM2NWI2OGQ3NDgxOWU2ZTIxNWVkY2Y0
10
+ OThkOTAxYTljNDIxNTQ2NzA5ZTY0ZTg0MmRmOWJmMjRkMzM3ZGE4YTg3OWVi
11
+ NDBlZjcyOGU1OGJjZDg2M2IzYmU5NDZlZmFkYzllY2FmMTk3YTc=
12
+ data.tar.gz: !binary |-
13
+ M2NkMjJkZWRmN2I1MWUyYWZlYzZhOTg1NTZlYjYyZWJkNmY2ODY1NjIxNzYx
14
+ YzQyMTI0Y2JjOWFmMzkwMTEzZDFhMTg3ZGJmM2MxMjM4OWI3YTk1OGQyMDU5
15
+ OTU1ZjgxZWUzODI0ZGMwNDQ4NzRkNWQyMWY4ZmY3NmVlN2I4Mzc=
data/README.md CHANGED
@@ -4,6 +4,8 @@ Persistent cache behaves like a hash, with a pluggable back-end. Currently sqlit
4
4
 
5
5
  Values in the cache have a default freshness period of 15465600 ms. This can be configured in the cache initializer. Setting fresh = nil indicates that data remains fresh for-ever. Each user of the cache may have his own independent freshness value. Not though that accessing a stale entry deletes it from the cache. You can use timestamp?(key) to read the timestamp of an entry. If stale data is requested from the cache, nil is returned. Data is marshalled before storage. If a key is not found in the cache, nil is returned. Setting the value of a key in the cache to nil deletes the entry. If required, creation time of an entry can be specified using set(key, value, timestamp)
6
6
 
7
+ Note that when using a back-end that requires marshalling (e.g. sqlite) the string encoding for []= and [] needs to be the same (e.g. UTF-8, US-ASCII, etc.) If the coding does not match, [] will not be able to find the entry during lookup and will return nil.
8
+
7
9
  This gem is sponsored by Hetzner (Pty) Ltd - http://hetzner.co.za
8
10
 
9
11
  ## StorageSQLite
@@ -61,6 +61,10 @@ module Persistent
61
61
  compile_value_path(key)
62
62
  end
63
63
 
64
+ def get_value_path_even_when_not_cached(key)
65
+ compile_value_path(key)
66
+ end
67
+
64
68
  def key_cached?(key)
65
69
  # don't read the value here, as it may be very large - rather look whether the key is present
66
70
  File.exists? compile_key_path(key)
@@ -1,5 +1,5 @@
1
1
  module Persistent
2
2
  class Cache
3
- VERSION = "0.1.8"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/multidb ADDED
Binary file
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.add_development_dependency 'rspec', '2.12.0'
18
18
  gem.add_development_dependency 'simplecov'
19
19
  gem.add_development_dependency 'simplecov-rcov'
20
+ gem.add_development_dependency 'debugger'
20
21
  gem.add_dependency 'sqlite3', '1.3.7'
21
22
  gem.add_dependency 'eh'
22
23
  end
@@ -15,8 +15,8 @@ describe Persistent::Cache do
15
15
  context "when constructing" do
16
16
  it "should receive database connection details and create a StorageSQLite instance if specified" do
17
17
  @pcache = Persistent::Cache.new(@db_name, Persistent::Cache::STORAGE_SQLITE)
18
- @pcache.class.should == Persistent::Cache
19
- @pcache.storage.is_a?(Persistent::StorageSQLite).should == true
18
+ expect(@pcache.class).to eq(Persistent::Cache)
19
+ expect(@pcache.storage.is_a?(Persistent::StorageSQLite)).to eq(true)
20
20
  end
21
21
 
22
22
  it "should raise an ArgumentError if storage details have not been provided" do
@@ -27,17 +27,17 @@ describe Persistent::Cache do
27
27
 
28
28
  it "should remember the freshness interval if provided" do
29
29
  @pcache = Persistent::Cache.new(@db_name, 123)
30
- @pcache.fresh.should == 123
30
+ expect(@pcache.fresh).to eq(123)
31
31
  end
32
32
 
33
33
  it "should remember the storage details provided" do
34
34
  @pcache = Persistent::Cache.new(@db_name, 123)
35
- @pcache.storage_details.should == @db_name
35
+ expect(@pcache.storage_details).to eq(@db_name)
36
36
  end
37
37
 
38
38
  it "should default the freshness interval to FRESH if not provided" do
39
39
  @pcache = Persistent::Cache.new(@db_name)
40
- @pcache.fresh.should == Persistent::Cache::FRESH
40
+ expect(@pcache.fresh).to eq(Persistent::Cache::FRESH)
41
41
  end
42
42
 
43
43
  it "should raise an ArgumentError if an unknown storage type has been provided" do
@@ -49,40 +49,40 @@ describe Persistent::Cache do
49
49
 
50
50
  context "When assigning a value to a key" do
51
51
  it "should ask the storage handler to first delete, then save the key/value pair" do
52
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
53
- @mock_storage.should_receive(:delete_entry)
54
- @mock_storage.should_receive(:save_key_value_pair).with(@test_key, @test_value, nil)
52
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
53
+ expect(@mock_storage).to receive(:delete_entry)
54
+ expect(@mock_storage).to receive(:save_key_value_pair).with(@test_key, @test_value, nil)
55
55
  @pcache = Persistent::Cache.new(@db_name)
56
56
  @pcache[@test_key] = @test_value
57
57
  end
58
58
 
59
59
  it "should ask the storage handler to delete if the value is nil using []" do
60
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
61
- @mock_storage.should_receive(:delete_entry).with(@test_key)
60
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
61
+ expect(@mock_storage).to receive(:delete_entry).with(@test_key)
62
62
  @pcache = Persistent::Cache.new(@db_name)
63
63
  @pcache[@test_key] = nil
64
64
  end
65
65
 
66
66
  it "should ask the storage handler to delete if the value is nil using set()" do
67
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
68
- @mock_storage.should_receive(:delete_entry).with(@test_key)
67
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
68
+ expect(@mock_storage).to receive(:delete_entry).with(@test_key)
69
69
  @pcache = Persistent::Cache.new(@db_name)
70
70
  @pcache.set(@test_key, nil, Time.now)
71
71
  end
72
72
 
73
73
  it "should serialize the key and value for persistence" do
74
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
75
- @mock_storage.should_receive(:delete_entry)
76
- @mock_storage.should_receive(:save_key_value_pair).with(@test_key, @test_value, nil)
74
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
75
+ expect(@mock_storage).to receive(:delete_entry)
76
+ expect(@mock_storage).to receive(:save_key_value_pair).with(@test_key, @test_value, nil)
77
77
  @pcache = Persistent::Cache.new(@db_name)
78
78
  @pcache[@test_key] = @test_value
79
79
  end
80
80
 
81
81
  it "should ask the storage handler to store the value, with a specific timestamp if specified" do
82
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
83
- @mock_storage.should_receive(:delete_entry)
82
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
83
+ expect(@mock_storage).to receive(:delete_entry)
84
84
  timestamp = Time.now - 100
85
- @mock_storage.should_receive(:save_key_value_pair).with(@test_key, @test_value, timestamp)
85
+ expect(@mock_storage).to receive(:save_key_value_pair).with(@test_key, @test_value, timestamp)
86
86
  @pcache = Persistent::Cache.new(@db_name)
87
87
  @pcache.set(@test_key, @test_value, timestamp)
88
88
  end
@@ -90,29 +90,29 @@ describe Persistent::Cache do
90
90
 
91
91
  context "When looking up a value given its key" do
92
92
  it "should retrieve the value from storage using lookup_key and deserialize the value" do
93
- @mock_storage.should_receive(:delete_entry)
94
- @mock_storage.should_receive(:save_key_value_pair).with(@test_key, @test_value, nil)
95
- @mock_storage.should_receive(:lookup_key).with(@test_key).and_return([@test_value, Time.now.to_s])
96
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
93
+ expect(@mock_storage).to receive(:delete_entry)
94
+ expect(@mock_storage).to receive(:save_key_value_pair).with(@test_key, @test_value, nil)
95
+ expect(@mock_storage).to receive(:lookup_key).with(@test_key).and_return([@test_value, Time.now.to_s])
96
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
97
97
  @pcache = Persistent::Cache.new(@db_name)
98
98
  @pcache[@test_key] = @test_value
99
99
  result = @pcache[@test_key]
100
- result.should == @test_value
100
+ expect(result).to eq(@test_value)
101
101
  end
102
102
 
103
103
  it "should return nil if a value exists but it not fresh" do
104
- @mock_storage.should_receive(:delete_entry)
105
- @mock_storage.should_receive(:lookup_key).with(@test_key).and_return([@test_value, (Time.now - Persistent::Cache::FRESH).to_s])
106
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
104
+ expect(@mock_storage).to receive(:delete_entry)
105
+ expect(@mock_storage).to receive(:lookup_key).with(@test_key).and_return([@test_value, (Time.now - Persistent::Cache::FRESH).to_s])
106
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
107
107
 
108
108
  @pcache = Persistent::Cache.new(@db_name)
109
- @pcache[@test_key].nil?.should == true
109
+ expect(@pcache[@test_key].nil?).to eq(true)
110
110
  end
111
111
 
112
112
  it "should remove from the cache an entry it encounters that is not fresh" do
113
- @mock_storage.should_receive(:delete_entry)
114
- @mock_storage.should_receive(:lookup_key).with(@test_key).and_return([@test_value, (Time.now - Persistent::Cache::FRESH).to_s])
115
- Persistent::StorageSQLite.should_receive(:new).and_return @mock_storage
113
+ expect(@mock_storage).to receive(:delete_entry)
114
+ expect(@mock_storage).to receive(:lookup_key).with(@test_key).and_return([@test_value, (Time.now - Persistent::Cache::FRESH).to_s])
115
+ expect(Persistent::StorageSQLite).to receive(:new).and_return(@mock_storage)
116
116
 
117
117
  @pcache = Persistent::Cache.new(@db_name)
118
118
  @pcache[@test_key]
@@ -121,13 +121,13 @@ describe Persistent::Cache do
121
121
  it "should return nil if a key is not in the database" do
122
122
  @pcache = Persistent::Cache.new(@db_name)
123
123
  result = @pcache["thiskeydoesnotexist"]
124
- result.nil?.should == true
124
+ expect(result.nil?).to eq(true)
125
125
  end
126
126
 
127
127
  it "should serialize the key for lookup" do
128
128
  @pcache = Persistent::Cache.new(@db_name)
129
129
  @pcache["testkey"] = "testvalue"
130
- @pcache.should_receive(:lookup_key).with("testkey")
130
+ expect(@pcache).to receive(:lookup_key).with("testkey")
131
131
  @pcache["testkey"]
132
132
  end
133
133
  end
@@ -135,12 +135,12 @@ describe Persistent::Cache do
135
135
  context "it should behave like a cache" do
136
136
  it "should return the correct size" do
137
137
  setup_cache
138
- @pcache.size.should == 3
138
+ expect(@pcache.size).to eq(3)
139
139
  end
140
140
 
141
141
  it "should return the list of keys when asked" do
142
142
  setup_cache
143
- @pcache.keys.should == ["one", "two", "three"]
143
+ expect(@pcache.keys).to eq(["one", "two", "three"])
144
144
  end
145
145
 
146
146
  it "should allow iteration through each" do
@@ -149,17 +149,17 @@ describe Persistent::Cache do
149
149
  @pcache.each do |key, value|
150
150
  test << "#{key} => #{value}"
151
151
  end
152
- test.should == ["one => value one", "two => value two", "three => value three"]
152
+ expect(test).to eq(["one => value one", "two => value two", "three => value three"])
153
153
  end
154
154
 
155
155
  it "should delete all entries in the database when asked to clear" do
156
156
  setup_cache
157
157
  @pcache.clear
158
- @pcache.size.should == 0
158
+ expect(@pcache.size).to eq(0)
159
159
  end
160
160
 
161
161
  it "should be able to handle multiple accesses to the same db" do
162
- pending "find a better way to test this, currently you need to spawn multiple rspecs running this test to hit the error if the busy_timeout is not specified"
162
+ #pending "find a better way to test this, currently you need to spawn multiple rspecs running this test to hit the error if the busy_timeout is not specified"
163
163
  pcache = Persistent::Cache.new("multidb")
164
164
  pcache["multi_test"] = 0
165
165
 
data/spec/spec_helper.rb CHANGED
@@ -14,9 +14,9 @@ require 'simplecov-rcov'
14
14
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'persistent-cache'))
15
15
 
16
16
  RSpec.configure do |config|
17
- config.treat_symbols_as_metadata_keys_with_true_values = true
18
17
  config.run_all_when_everything_filtered = true
19
18
  config.filter_run :focus
19
+ #config.expect_with(:rspec) { |c| c.syntax = :should }
20
20
 
21
21
  # Run specs in random order to surface order dependencies. If you find an
22
22
  # order dependency and want to debug it, you can fix the order by providing
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require "persistent-cache/storage/storage_directory"
3
+ require 'debugger'
3
4
 
4
5
  describe Persistent::StorageDirectory do
5
6
  before :each do
@@ -16,12 +17,14 @@ describe Persistent::StorageDirectory do
16
17
 
17
18
  context "when constructed" do
18
19
  it "should create the database if it does not exist" do
19
- File.exists?(@db_name).should be_true
20
+ #debugger
21
+ result = File.exists?(@db_name)
22
+ expect(result).to eq(true)
20
23
  end
21
24
 
22
25
  it "should propagate errors that are raised when failing to create a database" do
23
26
  delete_database
24
- FileUtils.should_receive(:makedirs).and_raise RuntimeError.new("testing")
27
+ expect(FileUtils).to receive(:makedirs).and_raise RuntimeError.new("testing")
25
28
  expect {
26
29
  @iut = Persistent::StorageDirectory.new(@db_name)
27
30
  }.to raise_error RuntimeError
@@ -33,11 +36,11 @@ describe Persistent::StorageDirectory do
33
36
  test_file = "#{@db_name}/hello"
34
37
  `touch #{test_file}`
35
38
  Persistent::StorageDirectory.new(@db_name)
36
- File.exist?(test_file).should == true
39
+ expect(File.exist?(test_file)).to eq(true)
37
40
  end
38
41
 
39
42
  it "should have a database" do
40
- @iut.is_a?(Persistent::StorageDirectory).should == true
43
+ expect(@iut.is_a?(Persistent::StorageDirectory)).to eq(true)
41
44
  end
42
45
 
43
46
  it "should raise an ArgumentError if storage details have not been provided" do
@@ -50,7 +53,7 @@ describe Persistent::StorageDirectory do
50
53
  context "when asked to store a key value pair" do
51
54
  it "should create a directory named the same as the key, in the storage root, if that directory does not exist, and store the value in a file called CACHE_FILE" do
52
55
  setup_test_entry
53
- read_file_content(@test_file).should == @test_data
56
+ expect(read_file_content(@test_file)).to eq(@test_data)
54
57
  end
55
58
 
56
59
  it "should default to storing the current time as the first line of the catalogue" do
@@ -64,16 +67,16 @@ describe Persistent::StorageDirectory do
64
67
  time = Time.now - 2500
65
68
  FileUtils.rm_f(@test_dir)
66
69
  @iut.save_key_value_pair(@test_key, @test_data, time)
67
- read_file_timestamp(@test_file).should == time.to_s
70
+ expect(read_file_timestamp(@test_file)).to eq(time.to_s)
68
71
  end
69
72
 
70
73
  it "should overwrite the existing key/value pair if they already exist" do
71
74
  FileUtils.rm_f(@test_dir)
72
75
  @iut.save_key_value_pair(@test_key, "old data")
73
76
  @iut.save_key_value_pair(@test_key, @test_data)
74
- File.exists?(@test_dir).should == true
75
- File.exists?(@test_file).should == true
76
- read_file_content(@test_file).should == @test_data
77
+ expect(File.exists?(@test_dir)).to eq(true)
78
+ expect(File.exists?(@test_file)).to eq(true)
79
+ expect(read_file_content(@test_file)).to eq(@test_data)
77
80
  end
78
81
 
79
82
  it "should raise an ArgumentError if the key is not a string" do
@@ -90,16 +93,16 @@ describe Persistent::StorageDirectory do
90
93
 
91
94
  it "should store the value exactly as given, regardless of newlines" do
92
95
  @iut.save_key_value_pair(@test_key, "some data")
93
- @iut.lookup_key(@test_key)[0][0].should == "some data"
96
+ expect(@iut.lookup_key(@test_key)[0][0]).to eq("some data")
94
97
 
95
98
  @iut.save_key_value_pair(@test_key, "some data\n")
96
- @iut.lookup_key(@test_key)[0][0].should == "some data\n"
99
+ expect(@iut.lookup_key(@test_key)[0][0]).to eq("some data\n")
97
100
 
98
101
  @iut.save_key_value_pair(@test_key, "some data\n\n")
99
- @iut.lookup_key(@test_key)[0][0].should == "some data\n\n"
102
+ expect(@iut.lookup_key(@test_key)[0][0]).to eq("some data\n\n")
100
103
 
101
104
  @iut.save_key_value_pair(@test_key, "\nline 1\n23456\n\n\nsome data\n")
102
- @iut.lookup_key(@test_key)[0][0].should == "\nline 1\n23456\n\n\nsome data\n"
105
+ expect(@iut.lookup_key(@test_key)[0][0]).to eq("\nline 1\n23456\n\n\nsome data\n")
103
106
  end
104
107
  end
105
108
 
@@ -107,20 +110,20 @@ describe Persistent::StorageDirectory do
107
110
  it "should retrieve the contents of the catalogue file from the database, excluding the timestamp" do
108
111
  setup_test_entry
109
112
  result = @iut.lookup_key(@test_key)
110
- result[0][0].should == @test_data
113
+ expect(result[0][0]).to eq(@test_data)
111
114
  end
112
115
 
113
116
  it "should retrieve the timestamp of the revision from the database" do
114
117
  now = Time.now
115
118
  setup_test_entry
116
119
  result = @iut.lookup_key(@test_key)
117
- result[0][1].should == now.to_s
120
+ expect(result[0][1]).to eq(now.to_s)
118
121
  end
119
122
 
120
123
  it "should return an empty array if a key is not in the database" do
121
124
  setup_test_entry
122
125
  result = @iut.lookup_key("thiskeyshouldnotexist")
123
- result.should == []
126
+ expect(result).to eq([])
124
127
  end
125
128
 
126
129
  it "should raise an ArgumentError if the key is not a string" do
@@ -138,9 +141,9 @@ describe Persistent::StorageDirectory do
138
141
  it "should delete the directory that results from the hash if it is present" do
139
142
  setup_test_entry
140
143
  @iut.delete_entry(@test_key)
141
- @iut.lookup_key(@test_key).should == []
142
- File.exists?(@test_dir).should == false
143
- File.exists?(@test_file).should == false
144
+ expect(@iut.lookup_key(@test_key)).to eq([])
145
+ expect(File.exists?(@test_dir)).to eq(false)
146
+ expect(File.exists?(@test_file)).to eq(false)
144
147
  end
145
148
 
146
149
  it "should raise an ArgumentError if the key is not a string" do
@@ -152,48 +155,48 @@ describe Persistent::StorageDirectory do
152
155
 
153
156
  context "when asked the size of the database" do
154
157
  it "should return 0 if the database has no entries" do
155
- @iut.size.should == 0
158
+ expect(@iut.size).to eq(0)
156
159
  end
157
160
 
158
161
  it "should return the number of entries" do
159
162
  populate_database
160
- @iut.size.should == 3
163
+ expect(@iut.size).to eq(3)
161
164
  end
162
165
 
163
166
  it "should return 0 if the database does not exist" do
164
167
  delete_database
165
- @iut.size.should == 0
168
+ expect(@iut.size).to eq(0)
166
169
  end
167
170
  end
168
171
 
169
172
  context "when asked for the keys in the database" do
170
173
  it "should return an empty array if there are no entries in the database" do
171
- @iut.keys.should == []
174
+ expect(@iut.keys).to eq([])
172
175
  end
173
176
 
174
177
  it "should return the keys (directories) in the database" do
175
178
  populate_database
176
- @iut.keys.should == [["one"], ["three"], ["two"]]
179
+ expect(@iut.keys).to eq([["one"], ["three"], ["two"]])
177
180
  end
178
181
 
179
182
  it "should return the keys in a sorted array" do
180
183
  populate_database
181
- @iut.keys.should == [["one"], ["three"], ["two"]]
184
+ expect(@iut.keys).to eq([["one"], ["three"], ["two"]])
182
185
  end
183
186
 
184
187
  it "should not return the storage root itself" do
185
188
  populate_database
186
189
  @iut.keys.each do |key|
187
- (key == "").should == false
188
- (key == "/").should == false
190
+ expect((key == "")).to eq(false)
191
+ expect((key == "/")).to eq(false)
189
192
  end
190
193
  end
191
194
 
192
195
  it "should return the keys in an array, with each key in its own sub-array" do
193
196
  populate_database
194
- @iut.keys.is_a?(Array).should == true
195
- @iut.keys[0].is_a?(Array).should == true
196
- @iut.keys[0][0].is_a?(String).should == true
197
+ expect(@iut.keys.is_a?(Array)).to eq(true)
198
+ expect(@iut.keys[0].is_a?(Array)).to eq(true)
199
+ expect(@iut.keys[0][0].is_a?(String)).to eq(true)
197
200
  end
198
201
  end
199
202
 
@@ -201,26 +204,26 @@ describe Persistent::StorageDirectory do
201
204
  it "should not delete the database root directory" do
202
205
  setup_test_entry
203
206
  @iut.clear
204
- File.exists?(@test_file).should == false
205
- File.exists?(@test_dir).should == false
206
- File.exist?(@iut.storage_root).should == true
207
+ expect(File.exists?(@test_file)).to eq(false)
208
+ expect(File.exists?(@test_dir)).to eq(false)
209
+ expect(File.exist?(@iut.storage_root)).to eq(true)
207
210
  end
208
211
 
209
212
  it "should delete all directories in the database" do
210
213
  populate_database
211
214
  @iut.clear
212
- @iut.size.should == 0
215
+ expect(@iut.size).to eq(0)
213
216
  end
214
217
  end
215
218
 
216
219
  context "when asked about the path to a key's cache value file" do
217
220
  it "should return nil if the key is not in the cache" do
218
- @iut.get_value_path(@test_key).should == nil
221
+ expect(@iut.get_value_path(@test_key)).to eq(nil)
219
222
  end
220
223
 
221
224
  it "should return the path to the key's cache value file if the key is in the cache" do
222
225
  @iut.save_key_value_pair(@test_key, @test_data)
223
- @iut.get_value_path(@test_key).should == @test_file
226
+ expect(@iut.get_value_path(@test_key)).to eq(@test_file)
224
227
  end
225
228
 
226
229
  it "should raise an ArgumentError if the key is not a string" do
@@ -239,13 +242,13 @@ describe Persistent::StorageDirectory do
239
242
  def setup_test_entry
240
243
  FileUtils.rm_f(@test_dir)
241
244
  @iut.save_key_value_pair(@test_key, @test_data)
242
- File.exists?(@test_dir).should == true
243
- File.exists?(@test_file).should == true
245
+ expect(File.exists?(@test_dir)).to eq(true)
246
+ expect(File.exists?(@test_file)).to eq(true)
244
247
  end
245
248
 
246
249
  def delete_database
247
250
  FileUtils.rm_rf(@db_name)
248
- File.exists?(@db_name).should == false
251
+ expect(File.exists?(@db_name)).to eq(false)
249
252
  end
250
253
 
251
254
  def read_file_data(file)
@@ -261,4 +264,4 @@ describe Persistent::StorageDirectory do
261
264
  result = File.read(file)
262
265
  result.lines.to_a[1..-1].join
263
266
  end
264
- end
267
+ end
@@ -10,8 +10,8 @@ describe Persistent::StorageRAM do
10
10
 
11
11
  context "when constructed" do
12
12
  it "should have a storage hash in RAM" do
13
- @iut.storage.nil?.should == false
14
- @iut.storage.instance_of?(Hash).should == true
13
+ expect(@iut.storage.nil?).to eql(false)
14
+ expect(@iut.storage.instance_of?(Hash)).to eql(true)
15
15
  end
16
16
  end
17
17
 
@@ -20,32 +20,33 @@ describe Persistent::StorageRAM do
20
20
  start_time = Time.now - 1
21
21
  @iut.save_key_value_pair(Marshal.dump(@test_key), Marshal.dump(@test_value))
22
22
  result = @iut.lookup_key(Marshal.dump(@test_key))
23
- result.nil?.should == false
24
- result[0].nil?.should == false
25
- result[0][0].should == Marshal.dump(@test_value)
23
+ expect(result.nil?).to eql(false)
24
+ expect(result[0].nil?).to eql(false)
25
+ expect(result[0][0]).to eql(Marshal.dump(@test_value))
26
26
  test_time = Time.parse(result[0][1])
27
- test_time.should > start_time and test_time.should < start_time + 600
27
+ expect(test_time).to be > start_time
28
+ expect(test_time).to be < start_time + 600
28
29
  end
29
30
 
30
31
  it "should store the key/value pair in RAM, with a timestamp specified" do
31
32
  test_time = (Time.now - 2500)
32
33
  @iut.save_key_value_pair(Marshal.dump(@test_key), Marshal.dump(@test_value), test_time)
33
34
  result = @iut.lookup_key(Marshal.dump(@test_key))
34
- result.nil?.should == false
35
- result[0].nil?.should == false
36
- result[0][0].should == Marshal.dump(@test_value)
35
+ expect(result.nil?).to eql(false)
36
+ expect(result[0].nil?).to eql(false)
37
+ expect(result[0][0]).to eql(Marshal.dump(@test_value))
37
38
  time_retrieved = Time.parse(result[0][1])
38
- time_retrieved.to_s.should == test_time.to_s
39
+ expect(time_retrieved.to_s).to eql(test_time.to_s)
39
40
  end
40
41
 
41
42
  it "should overwrite the existing key/value pair if they already exist" do
42
43
  @iut.save_key_value_pair(Marshal.dump(@test_key), Marshal.dump(@test_value))
43
44
  @iut.save_key_value_pair(Marshal.dump(@test_key), Marshal.dump("testvalue2"))
44
45
  result = @iut.lookup_key(Marshal.dump(@test_key))
45
- result.nil?.should == false
46
- result[0].nil?.should == false
47
- result.size.should == 1
48
- result[0][0].should == Marshal.dump("testvalue2")
46
+ expect(result.nil?).to eql(false)
47
+ expect(result[0].nil?).to eql(false)
48
+ expect(result.size).to eql(1)
49
+ expect(result[0][0]).to eql(Marshal.dump("testvalue2"))
49
50
  end
50
51
  end
51
52
 
@@ -53,7 +54,7 @@ describe Persistent::StorageRAM do
53
54
  it "should retrieve the value from RAM" do
54
55
  @iut.save_key_value_pair(Marshal.dump(@test_key), Marshal.dump(@test_value))
55
56
  result = @iut.lookup_key(Marshal.dump(@test_key))
56
- result[0][0].should == Marshal.dump(@test_value)
57
+ expect(result[0][0]).to eql(Marshal.dump(@test_value))
57
58
  end
58
59
 
59
60
  it "should retrieve the timestamp when the value was stored from RAM" do
@@ -61,14 +62,14 @@ describe Persistent::StorageRAM do
61
62
  @iut.save_key_value_pair(Marshal.dump(@test_key), Marshal.dump(@test_value))
62
63
  sleep 1
63
64
  result = @iut.lookup_key(Marshal.dump(@test_key))
64
- result[0][1].should == now
65
+ expect(result[0][1]).to eql(now)
65
66
  end
66
67
 
67
68
  it "should return an empty array if a key is not in RAM" do
68
69
  @iut.delete_entry(Marshal.dump(@test_key))
69
70
  result = @iut.lookup_key(Marshal.dump(@test_key))
70
- result.should == []
71
- result[0].should == nil
71
+ expect(result).to eql([])
72
+ expect(result[0]).to eql(nil)
72
73
  end
73
74
  end
74
75
 
@@ -80,36 +81,36 @@ describe Persistent::StorageRAM do
80
81
  it "should delete the entry if it is present" do
81
82
  @iut.save_key_value_pair(Marshal.dump(@test_key), Marshal.dump(@test_value))
82
83
  result = @iut.lookup_key(Marshal.dump(@test_key))
83
- result[0][0].should == Marshal.dump(@test_value)
84
+ expect(result[0][0]).to eql(Marshal.dump(@test_value))
84
85
  @iut.delete_entry(Marshal.dump(@test_key))
85
86
  result = @iut.lookup_key(Marshal.dump(@test_key))
86
- result.should == []
87
+ expect(result).to eql([])
87
88
  end
88
89
  end
89
90
 
90
91
  context "when asked the size of the RAM database" do
91
92
  it "should return 0 if the RAM database has no entries" do
92
- @iut.size.should == 0
93
+ expect(@iut.size).to eql(0)
93
94
  end
94
95
 
95
96
  it "should return the number of entries" do
96
97
  populate_database(@iut)
97
- @iut.size.should == 3
98
+ expect(@iut.size).to eql(3)
98
99
  end
99
100
  end
100
101
 
101
102
  context "when asked for the keys in the RAM database" do
102
103
  it "should return an empty array if there are no entries in the RAM database" do
103
- @iut.keys.should == []
104
+ expect(@iut.keys).to eql([])
104
105
  end
105
106
 
106
107
  it "should return the keys in the RAM database" do
107
108
  populate_database(@iut)
108
109
  keys = @iut.keys.flatten
109
- keys.include?(Marshal.dump("one")).should == true
110
- keys.include?(Marshal.dump("two")).should == true
111
- keys.include?(Marshal.dump("three")).should == true
112
- @iut.size.should == 3
110
+ expect(keys.include?(Marshal.dump("one"))).to eql(true)
111
+ expect(keys.include?(Marshal.dump("two"))).to eql(true)
112
+ expect(keys.include?(Marshal.dump("three"))).to eql(true)
113
+ expect(@iut.size).to eql(3)
113
114
  end
114
115
 
115
116
  it "should return the keys in an array, with each key in its own sub-array" do
@@ -117,7 +118,7 @@ describe Persistent::StorageRAM do
117
118
  found = false
118
119
  test = Marshal.dump("one")
119
120
  found = true if (@iut.keys[0][0] == test or @iut.keys[0][1] == test or @iut.keys[0][2] == test)
120
- found.should == true
121
+ expect(found).to eql(true)
121
122
  end
122
123
  end
123
124
 
@@ -125,7 +126,7 @@ describe Persistent::StorageRAM do
125
126
  it "should delete all entries in RAM" do
126
127
  populate_database(@iut)
127
128
  @iut.clear
128
- @iut.size.should == 0
129
+ expect(@iut.size).to eql(0)
129
130
  end
130
131
  end
131
132
 
@@ -12,18 +12,18 @@ describe Persistent::StorageSQLite do
12
12
 
13
13
  context "when constructed" do
14
14
  it "should create the database if it does not exist" do
15
- File.exists?(@db_name).should be_true
15
+ expect(File.exists?(@db_name)).to eq(true)
16
16
  end
17
17
 
18
18
  it "should create a key_value table with key (TEXT) and value (TEXT) and timestamp (TEXT) columns" do
19
19
  handle = SQLite3::Database.open(@db_name)
20
20
  result = handle.execute "PRAGMA table_info(#{Persistent::StorageSQLite::DB_TABLE})"
21
- result[0][1].should == "key"
22
- result[0][2].should == "TEXT"
23
- result[1][1].should == "value"
24
- result[1][2].should == "TEXT"
25
- result[2][1].should == "timestamp"
26
- result[2][2].should == "TEXT"
21
+ expect(result[0][1]).to eq("key")
22
+ expect(result[0][2]).to eq("TEXT")
23
+ expect(result[1][1]).to eq("value")
24
+ expect(result[1][2]).to eq("TEXT")
25
+ expect(result[2][1]).to eq("timestamp")
26
+ expect(result[2][2]).to eq("TEXT")
27
27
  end
28
28
 
29
29
 
@@ -35,19 +35,19 @@ describe Persistent::StorageSQLite do
35
35
  Persistent::StorageSQLite.new(@db_name)
36
36
  handle = SQLite3::Database.open(@db_name)
37
37
  result = handle.execute "select name from sqlite_master where type='table'"
38
- result[0][0].should == "test123"
38
+ expect(result[0][0]).to eq("test123")
39
39
  end
40
40
 
41
41
  it "should have a database handler" do
42
- @iut.storage_handler.is_a?(SQLite3::Database).should == true
42
+ expect(@iut.storage_handler.is_a?(SQLite3::Database)).to eq(true)
43
43
  end
44
44
 
45
45
  it "should set the SQLite busy timeout to DB_TIMEOUT" do
46
46
  delete_database
47
47
  mock_database = double(SQLite3::Database)
48
- mock_database.should_receive(:execute).at_least(0)
49
- mock_database.should_receive(:busy_timeout=).with(Persistent::StorageSQLite::DB_TIMEOUT)
50
- SQLite3::Database.should_receive(:new).and_return(mock_database)
48
+ expect(mock_database).to receive(:execute)
49
+ expect(mock_database).to receive(:busy_timeout=).with(Persistent::StorageSQLite::DB_TIMEOUT)
50
+ expect(SQLite3::Database).to receive(:new).and_return(mock_database)
51
51
  Persistent::StorageSQLite.new(@db_name)
52
52
  end
53
53
 
@@ -64,11 +64,12 @@ describe Persistent::StorageSQLite do
64
64
  @iut.save_key_value_pair(@test_key, @test_value)
65
65
  handle = SQLite3::Database.open(@db_name)
66
66
  result = handle.execute "select value, timestamp from #{Persistent::StorageSQLite::DB_TABLE} where key=?", Marshal.dump(@test_key)
67
- result.nil?.should == false
68
- result[0].nil?.should == false
69
- result[0][0].should == Marshal.dump(@test_value)
67
+ expect(result.nil?).to eq(false)
68
+ expect(result[0].nil?).to eq(false)
69
+ expect(result[0][0]).to eq(Marshal.dump(@test_value))
70
70
  test_time = Time.parse(result[0][1])
71
- test_time.should > start_time and test_time.should < start_time + 600
71
+ expect(test_time).to be > start_time
72
+ expect(test_time).to be < start_time + 600
72
73
  end
73
74
 
74
75
  it "should store the key/value pair in the db, with a timestamp specified" do
@@ -76,11 +77,11 @@ describe Persistent::StorageSQLite do
76
77
  @iut.save_key_value_pair(@test_key, @test_value, test_time)
77
78
  handle = SQLite3::Database.open(@db_name)
78
79
  result = handle.execute "select value, timestamp from #{Persistent::StorageSQLite::DB_TABLE} where key=?", Marshal.dump(@test_key)
79
- result.nil?.should == false
80
- result[0].nil?.should == false
81
- result[0][0].should == Marshal.dump(@test_value)
80
+ expect(result.nil?).to eq(false)
81
+ expect(result[0].nil?).to eq(false)
82
+ expect(result[0][0]).to eq(Marshal.dump(@test_value))
82
83
  time_retrieved = Time.parse(result[0][1])
83
- time_retrieved.to_s.should == test_time.to_s
84
+ expect(time_retrieved.to_s).to eq(test_time.to_s)
84
85
  end
85
86
 
86
87
  it "should overwrite the existing key/value pair if they already exist" do
@@ -88,10 +89,10 @@ describe Persistent::StorageSQLite do
88
89
  @iut.save_key_value_pair(@test_key, "testvalue2")
89
90
  handle = SQLite3::Database.open(@db_name)
90
91
  result = handle.execute "select value from #{Persistent::StorageSQLite::DB_TABLE} where key=?", Marshal.dump(@test_key)
91
- result.nil?.should == false
92
- result[0].nil?.should == false
93
- result.size.should == 1
94
- result[0][0].should == Marshal.dump("testvalue2")
92
+ expect(result.nil?).to eq(false)
93
+ expect(result[0].nil?).to eq(false)
94
+ expect(result.size).to eq(1)
95
+ expect(result[0][0]).to eq(Marshal.dump("testvalue2"))
95
96
  end
96
97
  end
97
98
 
@@ -99,7 +100,7 @@ describe Persistent::StorageSQLite do
99
100
  it "should retrieve the value from the database" do
100
101
  @iut.save_key_value_pair(@test_key, @test_value)
101
102
  result = @iut.lookup_key(@test_key)
102
- result[0].should == @test_value
103
+ expect(result[0]).to eq(@test_value)
103
104
  end
104
105
 
105
106
  it "should retrieve the timestamp when the value was stored from the database" do
@@ -107,13 +108,13 @@ describe Persistent::StorageSQLite do
107
108
  @iut.save_key_value_pair(@test_key, @test_value)
108
109
  sleep 1
109
110
  result = @iut.lookup_key(@test_key)
110
- result[1].should == now
111
+ expect(result[1]).to eq(now)
111
112
  end
112
113
 
113
114
  it "should return an empty array if a key is not in the database" do
114
115
  @iut.delete_entry(@test_key)
115
116
  result = @iut.lookup_key(@test_key)
116
- result.should == nil
117
+ expect(result).to eq(nil)
117
118
  end
118
119
  end
119
120
 
@@ -125,36 +126,36 @@ describe Persistent::StorageSQLite do
125
126
  it "should delete the entry if it is present" do
126
127
  @iut.save_key_value_pair(@test_key, @test_value)
127
128
  result = @iut.lookup_key(@test_key)
128
- result[0].should == @test_value
129
+ expect(result[0]).to eq(@test_value)
129
130
  @iut.delete_entry(@test_key)
130
131
  result = @iut.lookup_key(@test_key)
131
- result.should == nil
132
+ expect(result).to eq(nil)
132
133
  end
133
134
  end
134
135
 
135
136
  context "when asked the size of the database" do
136
137
  it "should return 0 if the database has no entries" do
137
- @iut.size.should == 0
138
+ expect(@iut.size).to eq(0)
138
139
  end
139
140
 
140
141
  it "should return the number of entries" do
141
142
  populate_database(@iut)
142
- @iut.size.should == 3
143
+ expect(@iut.size).to eq(3)
143
144
  end
144
145
  end
145
146
 
146
147
  context "when asked for the keys in the database" do
147
148
  it "should return an empty array if there are no entries in the database" do
148
- @iut.keys.should == []
149
+ expect(@iut.keys).to eq([])
149
150
  end
150
151
 
151
152
  it "should return the keys in the database" do
152
153
  populate_database(@iut)
153
154
  keys = @iut.keys.flatten
154
- keys.include?("one").should == true
155
- keys.include?("two").should == true
156
- keys.include?("three").should == true
157
- @iut.size.should == 3
155
+ expect(keys.include?("one")).to eq(true)
156
+ expect(keys.include?("two")).to eq(true)
157
+ expect(keys.include?("three")).to eq(true)
158
+ expect(@iut.size).to eq(3)
158
159
  end
159
160
 
160
161
  it "should return the keys in an array" do
@@ -162,7 +163,7 @@ describe Persistent::StorageSQLite do
162
163
  found = false
163
164
  test = "one"
164
165
  found = true if (@iut.keys.include?(test))
165
- found.should == true
166
+ expect(found).to eq(true)
166
167
  end
167
168
  end
168
169
 
@@ -170,13 +171,13 @@ describe Persistent::StorageSQLite do
170
171
  it "should not delete the database file" do
171
172
  populate_database(@iut)
172
173
  @iut.clear
173
- File.exists?(@db_name).should be_true
174
+ expect(File.exists?(@db_name)).to eq(true)
174
175
  end
175
176
 
176
177
  it "should delete all entries in the database" do
177
178
  populate_database(@iut)
178
179
  @iut.clear
179
- @iut.size.should == 0
180
+ expect(@iut.size).to eq(0)
180
181
  end
181
182
  end
182
183
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persistent-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Wynand van Dyk
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-07-30 00:00:00.000000000 Z
12
+ date: 2015-04-24 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - '='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - '='
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: simplecov
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ! '>='
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ! '>='
45
40
  - !ruby/object:Gem::Version
@@ -47,7 +42,6 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: simplecov-rcov
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ! '>='
53
47
  - !ruby/object:Gem::Version
@@ -55,7 +49,20 @@ dependencies:
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: debugger
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
59
66
  requirements:
60
67
  - - ! '>='
61
68
  - !ruby/object:Gem::Version
@@ -63,7 +70,6 @@ dependencies:
63
70
  - !ruby/object:Gem::Dependency
64
71
  name: sqlite3
65
72
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
73
  requirements:
68
74
  - - '='
69
75
  - !ruby/object:Gem::Version
@@ -71,7 +77,6 @@ dependencies:
71
77
  type: :runtime
72
78
  prerelease: false
73
79
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
80
  requirements:
76
81
  - - '='
77
82
  - !ruby/object:Gem::Version
@@ -79,7 +84,6 @@ dependencies:
79
84
  - !ruby/object:Gem::Dependency
80
85
  name: eh
81
86
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
87
  requirements:
84
88
  - - ! '>='
85
89
  - !ruby/object:Gem::Version
@@ -87,7 +91,6 @@ dependencies:
87
91
  type: :runtime
88
92
  prerelease: false
89
93
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
94
  requirements:
92
95
  - - ! '>='
93
96
  - !ruby/object:Gem::Version
@@ -112,6 +115,7 @@ files:
112
115
  - lib/persistent-cache/storage/storage_ram.rb
113
116
  - lib/persistent-cache/storage/storage_sq_lite.rb
114
117
  - lib/persistent-cache/version.rb
118
+ - multidb
115
119
  - persistent-cache.gemspec
116
120
  - spec/persistent-cache_spec.rb
117
121
  - spec/spec_helper.rb
@@ -120,27 +124,26 @@ files:
120
124
  - spec/storage/storage_sqlite_spec.rb
121
125
  homepage: ''
122
126
  licenses: []
127
+ metadata: {}
123
128
  post_install_message:
124
129
  rdoc_options: []
125
130
  require_paths:
126
131
  - lib
127
132
  required_ruby_version: !ruby/object:Gem::Requirement
128
- none: false
129
133
  requirements:
130
134
  - - ! '>='
131
135
  - !ruby/object:Gem::Version
132
136
  version: '0'
133
137
  required_rubygems_version: !ruby/object:Gem::Requirement
134
- none: false
135
138
  requirements:
136
139
  - - ! '>='
137
140
  - !ruby/object:Gem::Version
138
141
  version: '0'
139
142
  requirements: []
140
143
  rubyforge_project:
141
- rubygems_version: 1.8.28
144
+ rubygems_version: 2.2.1
142
145
  signing_key:
143
- specification_version: 3
146
+ specification_version: 4
144
147
  summary: Persistent Cache has a default freshness threshold of 179 days after which
145
148
  entries are no longer returned
146
149
  test_files: