redis-rack-cache 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Gemfile +2 -0
- data/README.md +47 -1
- data/gemfiles/rack_cache_1.6.gemfile +2 -1
- data/gemfiles/rack_cache_1.7.gemfile +2 -1
- data/lib/rack/cache/redis_base.rb +3 -0
- data/lib/rack/cache/redis_entitystore.rb +60 -2
- data/lib/redis-rack-cache.rb +1 -1
- data/lib/redis-rack-cache/version.rb +1 -1
- data/lib/zlib/gzip_compression.rb +32 -0
- data/redis-rack-cache.gemspec +2 -2
- data/test/fixtures/lorem.txt +99 -0
- data/test/rack/cache/entitystore/redis_test.rb +60 -10
- data/test/test_helper.rb +1 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0ea6d51a29498f3273430e69a7bc21faed3005e1b63ad2fd74aa1284c78e2bd
|
4
|
+
data.tar.gz: abc94191628bbca9d30d321be2208479fa147505fa76e2621dca0ce7bd4bbee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8e45b79c1cb106b1eccbdd528372dda9b70bacad1af4c8535e97334048d55a1e7ed854484e3e8cddcecd5d1e673139eef080acd2e1a19659d4a1af12885184
|
7
|
+
data.tar.gz: '05139f20d2a6e70798a223bf00a3ad6f6d66496f60f768f2cd010a268cd1091be5f8ac504f9f160fcfe34b3cd118fd1cda925d57560ece3cd436a641d9062734'
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -60,6 +60,52 @@ use Rack::Cache,
|
|
60
60
|
entitystore: 'redis://localhost:6380/0/entitystore'
|
61
61
|
```
|
62
62
|
|
63
|
+
### Compression
|
64
|
+
|
65
|
+
`Redis::Rack::Cache` supports data compression for entities over 1K when
|
66
|
+
transmitting back and forth over the wire to your Redis server.
|
67
|
+
Compressing data can improve bandwidth usage as well as RAM/storage
|
68
|
+
consumption, and is recommended if you operate a large-scale Rails
|
69
|
+
application.
|
70
|
+
|
71
|
+
To enable this feature, pass the `:compress` option when configuring
|
72
|
+
`Rack::Cache`:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Rails.application.configure do
|
76
|
+
config.action_dispatch.rack_cache = {
|
77
|
+
metastore: "#{Rails.credentials.redis_url}/1",
|
78
|
+
entitystore: "#{Rails.credentials.redis_url}/2",
|
79
|
+
compress: true
|
80
|
+
}
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
If compression is turned on, but no driver has been selected,
|
85
|
+
`Redis::Rack::Cache` will use Ruby's internal **ZLib** integrations and
|
86
|
+
compress entities with GZip. You can specify `:deflate` if you want to
|
87
|
+
use the deflate algorithm, `:gzip` if you want to be specific about it,
|
88
|
+
or a custom object that responds to `.deflate(data)` and
|
89
|
+
`.inflate(data)` to compress/decompress data, respectively. For example,
|
90
|
+
you can use Google's [Snappy](http://google.github.io/snappy/) for
|
91
|
+
[ludicrous-speed](https://www.youtube.com/watch?v=ygE01sOhzz0)
|
92
|
+
compression and decompression like this:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
Rails.application.configure do
|
96
|
+
config.action_dispatch.rack_cache = {
|
97
|
+
metastore: "#{Rails.credentials.redis_url}/1",
|
98
|
+
entitystore: "#{Rails.credentials.redis_url}/2",
|
99
|
+
compress: Snappy
|
100
|
+
}
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
**NOTE:** Since metadata would have to be marshalled before compression
|
105
|
+
in order to rehydrate it back into an object, only data stored in the
|
106
|
+
EntityStore is compressed for now. We'd love your feedback though,
|
107
|
+
let us know if there's a good use case for MetaStore compression!
|
108
|
+
|
63
109
|
## Development
|
64
110
|
|
65
111
|
First, get the project set up on your local machine:
|
@@ -70,7 +116,7 @@ cd redis-rack-cache
|
|
70
116
|
bundle install
|
71
117
|
```
|
72
118
|
|
73
|
-
You can run the following command to
|
119
|
+
You can run the following command to run the test suite:
|
74
120
|
|
75
121
|
```bash
|
76
122
|
bundle exec rake test
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rack/utils'
|
2
|
+
require 'rack/cache/options'
|
2
3
|
|
3
4
|
module Rack
|
4
5
|
module Cache
|
@@ -10,6 +11,8 @@ module Rack
|
|
10
11
|
|
11
12
|
attr_reader :cache, :options, :default_ttl
|
12
13
|
end
|
14
|
+
|
15
|
+
Rack::Cache::Options.option_accessor :compress
|
13
16
|
end
|
14
17
|
|
15
18
|
module ClassMethods
|
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'rack/cache/entity_store'
|
2
2
|
require 'redis-rack-cache/constants'
|
3
3
|
require 'rack/cache/redis_base'
|
4
|
+
require 'zlib'
|
5
|
+
require 'zlib/gzip_compression'
|
4
6
|
|
5
7
|
module Rack
|
6
8
|
module Cache
|
7
9
|
class EntityStore
|
8
10
|
class Redis < self
|
11
|
+
MINIMUM_COMPRESSION_BYTESIZE = 1_000
|
12
|
+
|
9
13
|
include RedisBase
|
10
14
|
|
11
15
|
def exist?(key)
|
@@ -13,15 +17,21 @@ module Rack
|
|
13
17
|
end
|
14
18
|
|
15
19
|
def read(key)
|
16
|
-
cache.get
|
20
|
+
raw = cache.get(key)
|
21
|
+
|
22
|
+
return if raw.nil?
|
23
|
+
|
24
|
+
decompress(raw).force_encoding('utf-8')
|
17
25
|
end
|
18
26
|
|
19
27
|
def write(body, ttl=0)
|
20
28
|
buf = StringIO.new
|
21
29
|
key, size = slurp(body) {|part| buf.write(part) }
|
22
30
|
ttl = ttl.to_i.zero? ? default_ttl : ttl
|
31
|
+
value = compress(buf.string)
|
32
|
+
|
33
|
+
return unless cache.setex(key, ttl, value)
|
23
34
|
|
24
|
-
return unless cache.setex(key, ttl, buf.string)
|
25
35
|
[key, size]
|
26
36
|
end
|
27
37
|
|
@@ -29,6 +39,54 @@ module Rack
|
|
29
39
|
cache.del key
|
30
40
|
nil
|
31
41
|
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def compress(data)
|
46
|
+
return data unless compress? data
|
47
|
+
|
48
|
+
deflater.deflate(data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def decompress(data)
|
52
|
+
return data unless compress?
|
53
|
+
|
54
|
+
inflater.inflate(data) rescue data
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def deflater
|
60
|
+
case options[:compress]
|
61
|
+
when :deflate
|
62
|
+
Zlib::Deflate
|
63
|
+
when :gzip, true
|
64
|
+
Zlib::GzipCompression
|
65
|
+
when false
|
66
|
+
nil
|
67
|
+
else
|
68
|
+
options[:compress]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def inflater
|
73
|
+
case options[:compress]
|
74
|
+
when :deflate
|
75
|
+
Zlib::Inflate
|
76
|
+
when :gzip, true
|
77
|
+
Zlib::GzipCompression
|
78
|
+
when false
|
79
|
+
nil
|
80
|
+
else
|
81
|
+
options[:compress]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def compress?(data = nil)
|
86
|
+
return options[:compress] if data.nil?
|
87
|
+
|
88
|
+
options[:compress] && data.bytesize >= MINIMUM_COMPRESSION_BYTESIZE
|
89
|
+
end
|
32
90
|
end
|
33
91
|
|
34
92
|
REDIS = REDISS = Redis
|
data/lib/redis-rack-cache.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Zlib
|
2
|
+
# Compress data over the wire to Redis with GZip. This code was mostly
|
3
|
+
# stolen from `Dalli::GzipCompressor`.
|
4
|
+
#
|
5
|
+
# https://github.com/petergoldstein/dalli/blob/master/lib/dalli/compressor.rb
|
6
|
+
module GzipCompression
|
7
|
+
# Compress the given data with GZip.
|
8
|
+
#
|
9
|
+
# @param [String] data - Uncompressed data.
|
10
|
+
# @return [String]
|
11
|
+
def self.deflate(data)
|
12
|
+
io = StringIO.new(String.new(""), "w")
|
13
|
+
gz = Zlib::GzipWriter.new(io)
|
14
|
+
|
15
|
+
gz.write(data)
|
16
|
+
gz.close
|
17
|
+
|
18
|
+
io.string
|
19
|
+
end
|
20
|
+
|
21
|
+
# Decompress the given data with GZip.
|
22
|
+
#
|
23
|
+
# @param [String] data - Compressed data.
|
24
|
+
# @return [String] Decompressed data.
|
25
|
+
def self.inflate(data)
|
26
|
+
io = StringIO.new(data, "rb")
|
27
|
+
gz = Zlib::GzipReader.new(io)
|
28
|
+
|
29
|
+
gz.read
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/redis-rack-cache.gemspec
CHANGED
@@ -17,12 +17,12 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = []
|
18
18
|
|
19
19
|
s.add_dependency 'redis-store', '>= 1.6', '< 2'
|
20
|
-
s.add_dependency 'rack-cache', '>= 1.
|
20
|
+
s.add_dependency 'rack-cache', '>= 1.10', '< 2'
|
21
21
|
|
22
22
|
s.add_development_dependency 'rake', '~> 10'
|
23
23
|
s.add_development_dependency 'bundler', '> 1', '< 3'
|
24
24
|
s.add_development_dependency 'mocha', '~> 0.14.0'
|
25
|
-
s.add_development_dependency 'minitest', '~> 5'
|
25
|
+
s.add_development_dependency 'minitest', '~> 5.11.0'
|
26
26
|
s.add_development_dependency 'redis-store-testing', '~> 0'
|
27
27
|
s.add_development_dependency 'appraisal', '~> 2'
|
28
28
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
Hic voluptatem unde. Eligendi soluta quia. Odit vel sed.
|
2
|
+
Iste veritatis debitis. Sunt vel quia. Nisi nemo quaerat.
|
3
|
+
Reprehenderit omnis et. Qui nemo suscipit. Officia consequatur dolor.
|
4
|
+
Et consequatur optio. Est expedita enim. Assumenda eveniet quam.
|
5
|
+
Explicabo expedita aut. Ea dolor ipsa. Omnis odit aut.
|
6
|
+
Est veniam molestiae. Porro ut nobis. Nisi eum nihil.
|
7
|
+
Neque non consequatur. Facere est libero. Consequuntur harum magni.
|
8
|
+
Accusantium iste esse. Reprehenderit doloribus odio. Cupiditate enim quis.
|
9
|
+
Provident perferendis adipisci. Sed nam fugit. Voluptate praesentium rerum.
|
10
|
+
Aut hic voluptas. Totam dolor ipsum. Neque vel debitis.
|
11
|
+
Cumque est animi. Molestiae praesentium dolor. Occaecati voluptates distinctio.
|
12
|
+
Omnis est non. Vel repellat enim. Et saepe tempora.
|
13
|
+
Dolor delectus veniam. Nostrum et laborum. Quod maiores reprehenderit.
|
14
|
+
Architecto optio debitis. Non eos repellat. Aut perspiciatis quos.
|
15
|
+
In voluptate voluptas. Est unde expedita. Est eum aut.
|
16
|
+
Voluptas deserunt illo. Laudantium nisi quia. Possimus accusamus aspernatur.
|
17
|
+
Accusamus maxime id. Rerum iste reprehenderit. Voluptatem tenetur totam.
|
18
|
+
Id aperiam ut. Tenetur sed nesciunt. Veritatis rerum neque.
|
19
|
+
Nam odio dolorum. Ipsum atque voluptatem. Fuga molestiae culpa.
|
20
|
+
Dicta esse harum. Id error autem. Pariatur autem quidem.
|
21
|
+
Eum sit qui. Voluptate hic minus. Voluptatem nisi cumque.
|
22
|
+
Est aut autem. In a quidem. Corporis illum sit.
|
23
|
+
Suscipit tenetur hic. Ipsa adipisci repellendus. Alias nesciunt veritatis.
|
24
|
+
Doloribus facilis repellat. Maiores alias voluptas. Officia et aut.
|
25
|
+
Qui ut sequi. Odit quas maiores. Qui doloribus tempore.
|
26
|
+
Illum aut sequi. Pariatur iusto placeat. Impedit ratione consequatur.
|
27
|
+
Odit inventore tenetur. Ea quasi assumenda. Quo sapiente mollitia.
|
28
|
+
Explicabo minima aperiam. Maiores voluptas aut. Ut in sed.
|
29
|
+
Optio modi temporibus. Quia aliquid accusantium. Animi commodi dolore.
|
30
|
+
Cum voluptatem saepe. Commodi dolorum perspiciatis. Porro et molestias.
|
31
|
+
Molestiae maxime rerum. Labore magnam porro. Est harum nam.
|
32
|
+
Voluptatem ex omnis. Dolorum ut consectetur. Dicta provident velit.
|
33
|
+
Commodi corporis ex. Libero recusandae expedita. Ut natus laborum.
|
34
|
+
Quae qui saepe. Quas recusandae voluptatem. Eum est est.
|
35
|
+
Laborum neque ut. Eos id pariatur. Eum ipsa qui.
|
36
|
+
Eveniet quo et. Aut quaerat velit. Maxime est aut.
|
37
|
+
A est soluta. Rerum sint recusandae. Voluptas dolorum asperiores.
|
38
|
+
Veritatis voluptas expedita. Non aut maiores. Mollitia dicta tempore.
|
39
|
+
Deleniti nam animi. Velit quae aut. Atque totam amet.
|
40
|
+
Ullam et dolor. Soluta aut voluptas. Eos et commodi.
|
41
|
+
Molestias asperiores placeat. Culpa sed magni. Minima aliquam quisquam.
|
42
|
+
Vel debitis perferendis. Voluptates incidunt non. Deserunt iusto aut.
|
43
|
+
Aut laboriosam voluptatem. Dolor nihil ea. Ratione praesentium beatae.
|
44
|
+
Officiis consequuntur qui. Corporis voluptas repellat. Porro minima officiis.
|
45
|
+
Dicta alias quos. Quos porro voluptates. Aut rem ut.
|
46
|
+
Ullam illo dolore. Magnam tempora corporis. Voluptatem assumenda nemo.
|
47
|
+
Quo inventore qui. Cumque eos facilis. Aut ab maiores.
|
48
|
+
Ipsa quia voluptatem. Magni nulla earum. Error vel iste.
|
49
|
+
Debitis eum quia. Placeat maiores iste. Vero ex iusto.
|
50
|
+
Fugit beatae quia. Omnis animi minima. Dolor iste error.
|
51
|
+
Provident quod occaecati. Voluptatem dicta possimus. Sunt commodi est.
|
52
|
+
Quasi in facere. Molestias omnis qui. Perspiciatis ipsa eum.
|
53
|
+
Veniam culpa sit. Molestiae quia cupiditate. Alias molestiae laborum.
|
54
|
+
Odit esse exercitationem. Magni accusantium qui. Autem odio corrupti.
|
55
|
+
Qui minus consequatur. Necessitatibus fugit voluptatum. Quia a sint.
|
56
|
+
Non quibusdam sed. Nihil dolor quo. Est consequatur perspiciatis.
|
57
|
+
Rerum rem expedita. Ab consectetur eos. Similique facere et.
|
58
|
+
Dolor autem natus. Ipsam illo eius. Sint tenetur corporis.
|
59
|
+
A ut aut. Odio sit esse. Unde dolores iste.
|
60
|
+
Quidem sed provident. Unde sint sunt. Quos praesentium cum.
|
61
|
+
Perferendis atque odio. Et quasi dolor. Et et facere.
|
62
|
+
Sunt praesentium aut. Rerum at optio. Totam iste et.
|
63
|
+
Natus ad vero. Autem dolores architecto. Ipsam eaque voluptatem.
|
64
|
+
In quaerat porro. Autem quos qui. Sit sint voluptas.
|
65
|
+
Sapiente omnis eos. Similique fuga minus. Dolore est id.
|
66
|
+
Inventore ea doloribus. Minima laboriosam adipisci. Ipsa voluptas aut.
|
67
|
+
Non cumque temporibus. Aut deleniti aperiam. Blanditiis delectus dolorem.
|
68
|
+
Delectus perferendis consequatur. Vel quos reprehenderit. Delectus non et.
|
69
|
+
Voluptates et atque. Excepturi voluptates cumque. Nam quas non.
|
70
|
+
Quia incidunt expedita. Itaque officiis necessitatibus. Sit nostrum perferendis.
|
71
|
+
Sed quibusdam consectetur. Reprehenderit nam qui. Hic rerum aperiam.
|
72
|
+
Praesentium quasi eaque. Reprehenderit temporibus dolor. Officia a quo.
|
73
|
+
Non porro cum. Provident repellendus dolore. Saepe commodi aut.
|
74
|
+
Placeat aut sunt. Illo et porro. Ea maiores quis.
|
75
|
+
Totam expedita assumenda. Dolorum voluptatibus iusto. Doloremque iste dolorem.
|
76
|
+
Ut corrupti eaque. Impedit tenetur eius. Voluptate id quia.
|
77
|
+
Laborum velit non. Et reprehenderit qui. Animi dicta voluptate.
|
78
|
+
Non quia quis. Minima id voluptas. Velit nihil sit.
|
79
|
+
Dolor praesentium eum. Tempora ullam repudiandae. At nihil harum.
|
80
|
+
Magni voluptatem sit. Harum et iure. Iure et voluptatem.
|
81
|
+
Architecto dignissimos quas. Et tenetur sint. Omnis recusandae aspernatur.
|
82
|
+
Et earum voluptatem. Temporibus possimus non. Id odio iusto.
|
83
|
+
Delectus cupiditate voluptatem. Sed expedita perferendis. Repudiandae qui iusto.
|
84
|
+
Doloremque totam ut. Aliquam maiores excepturi. Eius suscipit assumenda.
|
85
|
+
Quo aliquid sint. At impedit accusamus. Commodi et enim.
|
86
|
+
Pariatur iure optio. Corrupti nihil beatae. Unde consectetur quo.
|
87
|
+
Dolores et doloremque. Ut mollitia magnam. Omnis eius nihil.
|
88
|
+
Qui similique beatae. Rem quo pariatur. Earum perferendis vitae.
|
89
|
+
Qui nulla eum. Consequatur aut enim. Reiciendis earum aliquam.
|
90
|
+
Incidunt voluptas est. Nemo magnam recusandae. Eos placeat debitis.
|
91
|
+
Aliquam qui aut. Quo est cupiditate. Et nobis est.
|
92
|
+
Iusto omnis eos. Illo voluptatem excepturi. Quae velit a.
|
93
|
+
Consequatur inventore qui. Sapiente totam dicta. Molestiae accusamus autem.
|
94
|
+
Neque provident laudantium. Ut minus est. Veritatis enim et.
|
95
|
+
Vel et in. Consequatur deleniti aut. Cupiditate et non.
|
96
|
+
Eos fugiat veniam. Consequatur pariatur et. Sed occaecati et.
|
97
|
+
Quia quasi quis. Aut repudiandae amet. Ut rerum dignissimos.
|
98
|
+
Sed saepe quis. Ipsa a repellat. Consequatur assumenda modi.
|
99
|
+
Velit cupiditate corrupti. Et commodi ducimus. Occaecati repudiandae velit.
|
@@ -9,6 +9,56 @@ end
|
|
9
9
|
describe Rack::Cache::EntityStore::Redis do
|
10
10
|
before do
|
11
11
|
@store = ::Rack::Cache::EntityStore::Redis.new :host => 'localhost'
|
12
|
+
@body = File.read('test/fixtures/lorem.txt')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'stores raw data by default' do
|
16
|
+
key, _size = @store.write [@body]
|
17
|
+
|
18
|
+
key.wont_be_nil
|
19
|
+
@store.read(key).must_equal(@body)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'compresses data with deflate' do
|
23
|
+
@store.options[:compress] = :deflate
|
24
|
+
key, _size = @store.write [@body]
|
25
|
+
|
26
|
+
key.wont_be_nil
|
27
|
+
@store.read(key).must_equal(@body)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'compresses data with gzip' do
|
31
|
+
@store.options[:compress] = :gzip
|
32
|
+
key, _size = @store.write [@body]
|
33
|
+
|
34
|
+
key.wont_be_nil
|
35
|
+
|
36
|
+
@store.options[:compress] = true
|
37
|
+
|
38
|
+
@store.read(key).must_equal(@body)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'compresses data with custom tool' do
|
42
|
+
@store.options[:compress] = Snappy
|
43
|
+
key, _size = @store.write [@body]
|
44
|
+
|
45
|
+
key.wont_be_nil
|
46
|
+
@store.read(key).must_equal(@body)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'handles existing non-compressed data' do
|
50
|
+
@store.options[:compress] = true
|
51
|
+
key, _size = @store.send(:slurp, [@body]) {}
|
52
|
+
|
53
|
+
@store.cache.setex(key, 120, @body).must_equal('OK')
|
54
|
+
@store.read(key).must_equal(@body)
|
55
|
+
|
56
|
+
@store.options[:compress] = Snappy
|
57
|
+
|
58
|
+
key, _size = @store.send(:slurp, [@body]) {}
|
59
|
+
|
60
|
+
@store.cache.setex(key, 120, @body).must_equal('OK')
|
61
|
+
@store.read(key).must_equal(@body)
|
12
62
|
end
|
13
63
|
|
14
64
|
it 'respects the default_tll options' do
|
@@ -18,7 +68,7 @@ describe Rack::Cache::EntityStore::Redis do
|
|
18
68
|
|
19
69
|
it 'properly delegates the TTL to redis' do
|
20
70
|
@store = ::Rack::Cache::EntityStore::Redis.new({ :host => 'localhost' }, { :default_ttl => 120 })
|
21
|
-
key,
|
71
|
+
key, _size = @store.write(['She rode to the devil,'])
|
22
72
|
assert @store.cache.ttl(key) <= 120
|
23
73
|
end
|
24
74
|
|
@@ -56,7 +106,7 @@ describe Rack::Cache::EntityStore::Redis do
|
|
56
106
|
end
|
57
107
|
|
58
108
|
it 'stores bodies with #write' do
|
59
|
-
key,
|
109
|
+
key, _size = @store.write(['My wild love went riding,'])
|
60
110
|
key.wont_be_nil
|
61
111
|
key.must_be :sha_like?
|
62
112
|
|
@@ -65,7 +115,7 @@ describe Rack::Cache::EntityStore::Redis do
|
|
65
115
|
end
|
66
116
|
|
67
117
|
it 'takes a ttl parameter for #write' do
|
68
|
-
key,
|
118
|
+
key, _size = @store.write(['My wild love went riding,'], 0)
|
69
119
|
key.wont_be_nil
|
70
120
|
key.must_be :sha_like?
|
71
121
|
|
@@ -74,19 +124,19 @@ describe Rack::Cache::EntityStore::Redis do
|
|
74
124
|
end
|
75
125
|
|
76
126
|
it 'correctly determines whether cached body exists for key with #exist?' do
|
77
|
-
key,
|
127
|
+
key, _size = @store.write(['She rode to the devil,'])
|
78
128
|
assert @store.exist?(key)
|
79
129
|
assert ! @store.exist?('938jasddj83jasdh4438021ksdfjsdfjsdsf')
|
80
130
|
end
|
81
131
|
|
82
132
|
it 'can read data written with #write' do
|
83
|
-
key,
|
133
|
+
key, _size = @store.write(['And asked him to pay.'])
|
84
134
|
data = @store.read(key)
|
85
135
|
data.must_equal('And asked him to pay.')
|
86
136
|
end
|
87
137
|
|
88
138
|
it 'gives a 40 character SHA1 hex digest from #write' do
|
89
|
-
key,
|
139
|
+
key, _size = @store.write(['she rode to the sea;'])
|
90
140
|
key.wont_be_nil
|
91
141
|
key.length.must_equal(40)
|
92
142
|
key.must_match(/^[0-9a-z]+$/)
|
@@ -94,7 +144,7 @@ describe Rack::Cache::EntityStore::Redis do
|
|
94
144
|
end
|
95
145
|
|
96
146
|
it 'returns the entire body as a String from #read' do
|
97
|
-
key,
|
147
|
+
key, _size = @store.write(['She gathered together'])
|
98
148
|
@store.read(key).must_equal('She gathered together')
|
99
149
|
end
|
100
150
|
|
@@ -103,7 +153,7 @@ describe Rack::Cache::EntityStore::Redis do
|
|
103
153
|
end
|
104
154
|
|
105
155
|
it 'returns a Rack compatible body from #open' do
|
106
|
-
key,
|
156
|
+
key, _size = @store.write(['Some shells for her hair.'])
|
107
157
|
body = @store.open(key)
|
108
158
|
body.must_respond_to :each
|
109
159
|
buf = ''
|
@@ -118,7 +168,7 @@ describe Rack::Cache::EntityStore::Redis do
|
|
118
168
|
if RUBY_VERSION < '1.9'
|
119
169
|
it 'can store largish bodies with binary data' do
|
120
170
|
pony = File.open(File.dirname(__FILE__) + '/pony.jpg', 'rb') { |f| f.read }
|
121
|
-
key,
|
171
|
+
key, _size = @store.write([pony])
|
122
172
|
key.must_equal('d0f30d8659b4d268c5c64385d9790024c2d78deb')
|
123
173
|
data = @store.read(key)
|
124
174
|
data.length.must_equal(pony.length)
|
@@ -127,7 +177,7 @@ describe Rack::Cache::EntityStore::Redis do
|
|
127
177
|
end
|
128
178
|
|
129
179
|
it 'deletes stored entries with #purge' do
|
130
|
-
key,
|
180
|
+
key, _size = @store.write(['My wild love went riding,'])
|
131
181
|
@store.purge(key).must_be_nil
|
132
182
|
@store.read(key).must_be_nil
|
133
183
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-rack-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-store
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '1.
|
39
|
+
version: '1.10'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '2'
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '1.
|
49
|
+
version: '1.10'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2'
|
@@ -104,14 +104,14 @@ dependencies:
|
|
104
104
|
requirements:
|
105
105
|
- - "~>"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
107
|
+
version: 5.11.0
|
108
108
|
type: :development
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
112
|
- - "~>"
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
114
|
+
version: 5.11.0
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: redis-store-testing
|
117
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +164,9 @@ files:
|
|
164
164
|
- lib/redis-rack-cache.rb
|
165
165
|
- lib/redis-rack-cache/constants.rb
|
166
166
|
- lib/redis-rack-cache/version.rb
|
167
|
+
- lib/zlib/gzip_compression.rb
|
167
168
|
- redis-rack-cache.gemspec
|
169
|
+
- test/fixtures/lorem.txt
|
168
170
|
- test/rack/cache/entitystore/pony.jpg
|
169
171
|
- test/rack/cache/entitystore/redis_test.rb
|
170
172
|
- test/rack/cache/metastore/redis_test.rb
|