coffee_table 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +0 -10
- data/Gemfile.lock +24 -21
- data/README.textile +1 -2
- data/changelog.txt +3 -0
- data/coffee_table.gemspec +4 -1
- data/lib/coffee_table.rb +6 -21
- data/lib/coffee_table/utility.rb +1 -2
- data/lib/coffee_table/version.rb +1 -1
- data/spec/lib/coffee_table_spec.rb +9 -9
- data/spec/lib/key_spec.rb +4 -4
- metadata +46 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b61f44f08291532c47af511b52cea6e4ae43abc
|
4
|
+
data.tar.gz: f86c99825f3e14a20786c4f221032663d3c6cc9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3ac7bcc8fb7a9830ca44d1f807b6ed598d104bd8b44ac23cf69dd4ade1c6052a433f065f796eb23a9d90401f44175837bc00affb59eac38c7eea9b1cfc47427
|
7
|
+
data.tar.gz: da3ab9a81e3f32f09a7eaf5ff3cb2214cb568ad5b18e51aafdccdfa83ee9cb44430b09d1a0daeecd25e0b2aa5c89a2cf20e7c3b85bf4099162146f604cb0fd54
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.4.1
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coffee_table (0.2.
|
4
|
+
coffee_table (0.2.8)
|
5
5
|
activesupport
|
6
6
|
gzip
|
7
7
|
redis
|
8
|
-
|
8
|
+
redis-namespace
|
9
9
|
sourcify
|
10
10
|
|
11
11
|
GEM
|
12
12
|
remote: http://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activesupport (
|
15
|
-
|
16
|
-
|
14
|
+
activesupport (5.1.4)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (~> 0.7)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
17
19
|
awesome_print (1.1.0)
|
18
20
|
colorize (0.5.8)
|
21
|
+
concurrent-ruby (1.0.5)
|
19
22
|
coveralls (0.6.7)
|
20
23
|
colorize
|
21
24
|
multi_json (~> 1.3)
|
@@ -23,14 +26,17 @@ GEM
|
|
23
26
|
simplecov (>= 0.7)
|
24
27
|
thor
|
25
28
|
diff-lcs (1.2.4)
|
26
|
-
file-tail (1.
|
29
|
+
file-tail (1.2.0)
|
27
30
|
tins (~> 1.0)
|
28
31
|
gzip (1.0)
|
29
|
-
i18n (0.6
|
32
|
+
i18n (0.8.6)
|
30
33
|
mime-types (1.23)
|
34
|
+
minitest (5.10.3)
|
31
35
|
mock_redis (0.17.0)
|
32
36
|
multi_json (1.7.8)
|
33
|
-
redis (3.
|
37
|
+
redis (3.3.3)
|
38
|
+
redis-namespace (1.5.3)
|
39
|
+
redis (~> 3.0, >= 3.0.4)
|
34
40
|
rest-client (1.6.7)
|
35
41
|
mime-types (>= 1.16)
|
36
42
|
rspec (2.14.1)
|
@@ -41,14 +47,12 @@ GEM
|
|
41
47
|
rspec-expectations (2.14.1)
|
42
48
|
diff-lcs (>= 1.1.3, < 2.0)
|
43
49
|
rspec-mocks (2.14.3)
|
44
|
-
ruby2ruby (2.
|
50
|
+
ruby2ruby (2.4.0)
|
45
51
|
ruby_parser (~> 3.1)
|
46
|
-
sexp_processor (~> 4.
|
47
|
-
ruby_parser (3.
|
48
|
-
sexp_processor (~> 4.
|
49
|
-
|
50
|
-
tzinfo (>= 0.3.23)
|
51
|
-
sexp_processor (4.7.0)
|
52
|
+
sexp_processor (~> 4.6)
|
53
|
+
ruby_parser (3.10.1)
|
54
|
+
sexp_processor (~> 4.9)
|
55
|
+
sexp_processor (4.10.0)
|
52
56
|
simplecov (0.7.1)
|
53
57
|
multi_json (~> 1.0)
|
54
58
|
simplecov-html (~> 0.7.1)
|
@@ -60,22 +64,21 @@ GEM
|
|
60
64
|
sexp_processor (>= 3.0.5)
|
61
65
|
spork (0.9.2)
|
62
66
|
thor (0.18.1)
|
63
|
-
|
64
|
-
|
67
|
+
thread_safe (0.3.6)
|
68
|
+
tins (1.15.0)
|
69
|
+
tzinfo (1.2.3)
|
70
|
+
thread_safe (~> 0.1)
|
65
71
|
|
66
72
|
PLATFORMS
|
67
73
|
ruby
|
68
74
|
|
69
75
|
DEPENDENCIES
|
70
|
-
activesupport
|
71
76
|
awesome_print
|
72
77
|
coffee_table!
|
73
78
|
coveralls
|
74
|
-
gzip
|
75
79
|
mock_redis
|
76
80
|
rspec
|
77
|
-
rufus-scheduler
|
78
81
|
spork
|
79
82
|
|
80
83
|
BUNDLED WITH
|
81
|
-
1.
|
84
|
+
1.15.4
|
data/README.textile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
h1. CoffeeTable v0.2.
|
2
|
+
h1. CoffeeTable v0.2.8
|
3
3
|
|
4
4
|
!https://badge.fury.io/rb/coffee_table.png!:http://badge.fury.io/rb/coffee_table
|
5
5
|
!https://gemnasium.com/stewartmckee/coffee_table.png!
|
@@ -39,7 +39,6 @@ Creates a new cache object. You can pass options into this method to modify the
|
|
39
39
|
* :ignore_code_changes defaults to false. By default a md5 hash of the code in the block is included in the key, if you change the code, the key automatically invalidates. This is to protect against code changes that won't be picked up due to the cache returning.
|
40
40
|
* :compress_content defaults to true and sets whether large strings are compressed
|
41
41
|
* :compress_min_size defaults to 10240, which is 10k any strings larger than this are compressed before being stored
|
42
|
-
* :max_threads defaults to 28, if running in limited thread environment you can reduce this (eg Heroku)
|
43
42
|
|
44
43
|
h4. fetch(initial_key, *related_objects, &block)
|
45
44
|
|
data/changelog.txt
CHANGED
data/coffee_table.gemspec
CHANGED
@@ -20,8 +20,11 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "mock_redis"
|
24
|
+
s.add_development_dependency "spork"
|
25
|
+
s.add_development_dependency "coveralls"
|
23
26
|
s.add_dependency "redis"
|
24
|
-
s.add_dependency "
|
27
|
+
s.add_dependency "redis-namespace"
|
25
28
|
s.add_dependency "activesupport"
|
26
29
|
s.add_dependency "sourcify"
|
27
30
|
s.add_dependency "gzip"
|
data/lib/coffee_table.rb
CHANGED
@@ -5,10 +5,11 @@ require "coffee_table/invalid_object_error"
|
|
5
5
|
require "coffee_table/block_missing_error"
|
6
6
|
require "coffee_table/object_definition"
|
7
7
|
require "redis"
|
8
|
-
require '
|
8
|
+
require 'redis-namespace'
|
9
9
|
require 'active_support/inflector'
|
10
10
|
require 'digest/md5'
|
11
11
|
require 'gzip'
|
12
|
+
require 'awesome_print'
|
12
13
|
|
13
14
|
module CoffeeTable
|
14
15
|
class Cache
|
@@ -27,20 +28,13 @@ module CoffeeTable
|
|
27
28
|
default_ignore_code_changes_to false
|
28
29
|
default_compress_content_to true
|
29
30
|
default_compress_min_size_to 10240
|
30
|
-
default_max_threads_to 5
|
31
31
|
|
32
32
|
if !@options[:redis].nil?
|
33
|
-
|
33
|
+
@redis = Redis::Namespace.new(@options[:redis_namespace], :redis => @options[:redis])
|
34
34
|
elsif @options.has_key?(:redis_url)
|
35
|
-
@redis = Redis.new({:url => @options[:redis_url]})
|
35
|
+
@redis = Redis::Namespace.new(@options[:redis_namespace], {:url => @options[:redis_url]})
|
36
36
|
else
|
37
|
-
@redis = Redis.new({:server => @options[:redis_server], :port => @options[:redis_port]})
|
38
|
-
end
|
39
|
-
rufus_version = Gem::Version.new(Rufus::Scheduler::VERSION)
|
40
|
-
if rufus_version >= Gem::Version.new('3.0.0')
|
41
|
-
@scheduler = Rufus::Scheduler.new(:max_work_threads => @options[:max_threads])
|
42
|
-
else
|
43
|
-
@scheduler = Rufus::Scheduler.start_new
|
37
|
+
@redis = Redis::Namespace.new(@options[:redis_namespace], {:server => @options[:redis_server], :port => @options[:redis_port]})
|
44
38
|
end
|
45
39
|
end
|
46
40
|
|
@@ -67,8 +61,6 @@ module CoffeeTable
|
|
67
61
|
|
68
62
|
flags = {}
|
69
63
|
|
70
|
-
|
71
|
-
|
72
64
|
# if first related_object is integer or fixnum it is used as an expiry time for the cache object
|
73
65
|
key = CoffeeTable::Key.new(initial_key, block_key, flags, related_objects)
|
74
66
|
if @options[:enable_cache]
|
@@ -91,19 +83,13 @@ module CoffeeTable
|
|
91
83
|
|
92
84
|
if compress_result
|
93
85
|
key.add_flag(:compressed => true)
|
94
|
-
@redis.sadd "cache_keys", key.to_s
|
95
86
|
@redis.set(key.to_s, Marshal.dump(result.gzip))
|
96
87
|
else
|
97
|
-
@redis.sadd "cache_keys", key.to_s
|
98
88
|
@redis.set(key.to_s, Marshal.dump(result))
|
99
89
|
end
|
100
90
|
|
101
91
|
unless expiry.nil?
|
102
92
|
@redis.expire key.to_s, expiry
|
103
|
-
@scheduler.in "#{expiry}s" do
|
104
|
-
@redis.del(key.to_s)
|
105
|
-
@redis.srem "cache_keys", key.to_s
|
106
|
-
end
|
107
93
|
end
|
108
94
|
end
|
109
95
|
end
|
@@ -116,7 +102,6 @@ module CoffeeTable
|
|
116
102
|
def expire_key(key_value)
|
117
103
|
keys.map{|k| CoffeeTable::Key.parse(k)}.select{|key| key.has_element?(key_value) || key.to_s == key_value }.each do |key|
|
118
104
|
@redis.del(key.to_s)
|
119
|
-
@redis.srem "cache_keys", key.to_s
|
120
105
|
end
|
121
106
|
end
|
122
107
|
|
@@ -125,7 +110,7 @@ module CoffeeTable
|
|
125
110
|
end
|
126
111
|
|
127
112
|
def keys
|
128
|
-
@redis.
|
113
|
+
@redis.keys
|
129
114
|
end
|
130
115
|
|
131
116
|
def expire_for(*objects)
|
data/lib/coffee_table/utility.rb
CHANGED
data/lib/coffee_table/version.rb
CHANGED
@@ -50,12 +50,12 @@ describe CoffeeTable::Cache do
|
|
50
50
|
context "compressing" do
|
51
51
|
|
52
52
|
before(:each) do
|
53
|
-
@redis = Redis.new({:server => "127.0.0.1", :port => 6379})
|
53
|
+
@redis = Redis::Namespace.new("coffee_table", {:server => "127.0.0.1", :port => 6379})
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "compresses on strings greater than limit" do
|
58
|
-
@coffee_table = CoffeeTable::Cache.new(:compress_min_size => 20)
|
58
|
+
@coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
|
59
59
|
zipped_content = "this string should be long".gzip
|
60
60
|
result = @coffee_table.fetch(:test_key) do
|
61
61
|
"this string should be long"
|
@@ -64,7 +64,7 @@ describe CoffeeTable::Cache do
|
|
64
64
|
@redis.get("test_key|1c083b7ed4b406f263ef329a608a80b9|compressed=true").should eq Marshal.dump(zipped_content)
|
65
65
|
end
|
66
66
|
it "does not compress on non strings" do
|
67
|
-
@coffee_table = CoffeeTable::Cache.new(:compress_min_size => 20)
|
67
|
+
@coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
|
68
68
|
result = @coffee_table.fetch(:test_key) do
|
69
69
|
{:test => "this value is a decent length to trigger compress"}
|
70
70
|
end
|
@@ -73,7 +73,7 @@ describe CoffeeTable::Cache do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "does not compress when turned off" do
|
76
|
-
@coffee_table = CoffeeTable::Cache.new(:compress_content => false)
|
76
|
+
@coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_content => false)
|
77
77
|
result = @coffee_table.fetch(:test_key) do
|
78
78
|
"this string should be long"
|
79
79
|
end
|
@@ -81,7 +81,7 @@ describe CoffeeTable::Cache do
|
|
81
81
|
@redis.get("test_key|1c083b7ed4b406f263ef329a608a80b9|").should eql Marshal.dump("this string should be long")
|
82
82
|
end
|
83
83
|
it "does not compress on strings below limit" do
|
84
|
-
@coffee_table = CoffeeTable::Cache.new(:compress_min_size => 20)
|
84
|
+
@coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
|
85
85
|
result = @coffee_table.fetch(:test_key) do
|
86
86
|
"short"
|
87
87
|
end
|
@@ -89,7 +89,7 @@ describe CoffeeTable::Cache do
|
|
89
89
|
@redis.get("test_key|f0b9a08ff52e14e59daa03aae70a5cab|").should eql Marshal.dump("short")
|
90
90
|
end
|
91
91
|
it "decompresses compressed value" do
|
92
|
-
@coffee_table = CoffeeTable::Cache.new(:compress_min_size => 20)
|
92
|
+
@coffee_table = CoffeeTable::Cache.new(:redis => @redis, :compress_min_size => 20)
|
93
93
|
@coffee_table.fetch(:test_key) do
|
94
94
|
"this string should be long"
|
95
95
|
end
|
@@ -101,7 +101,7 @@ describe CoffeeTable::Cache do
|
|
101
101
|
|
102
102
|
end
|
103
103
|
it "does not decompress a non compressed value" do
|
104
|
-
@coffee_table = CoffeeTable::Cache.new(:compress_min_size => 20)
|
104
|
+
@coffee_table = CoffeeTable::Cache.new(:redis => @redis, :compress_min_size => 20)
|
105
105
|
@coffee_table.fetch(:test_key) do
|
106
106
|
"short"
|
107
107
|
end
|
@@ -197,11 +197,11 @@ describe CoffeeTable::Cache do
|
|
197
197
|
end
|
198
198
|
context "with expiry" do
|
199
199
|
it "keys should update when cache expires" do
|
200
|
-
@coffee_table.fetch(:test_key, :expiry =>
|
200
|
+
@coffee_table.fetch(:test_key, :expiry => 1) do
|
201
201
|
"object1"
|
202
202
|
end
|
203
203
|
@coffee_table.keys.count.should == 1
|
204
|
-
sleep
|
204
|
+
sleep 1
|
205
205
|
@coffee_table.keys.count.should == 0
|
206
206
|
end
|
207
207
|
it "should not execute block during cache period" do
|
data/spec/lib/key_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe CoffeeTable::Key do
|
4
|
-
|
4
|
+
|
5
5
|
context "has correct methods" do
|
6
6
|
it "should have a parse class method" do
|
7
7
|
CoffeeTable::Key.should respond_to :parse
|
@@ -43,7 +43,7 @@ describe CoffeeTable::Key do
|
|
43
43
|
key.elements[0].should == "sample_|s&class"
|
44
44
|
|
45
45
|
key.to_s.should == "te|s&t|asdf|s&|sample_|s&class|"
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -109,8 +109,8 @@ describe CoffeeTable::Key do
|
|
109
109
|
it "does not match on flag values" do
|
110
110
|
key = CoffeeTable::Key.new("name", "key", {:option => "value", :option2 => "value2"}, @obj1, @obj2, @obj3)
|
111
111
|
key.has_element?("option=value&option2=value2").should be_false
|
112
|
-
|
112
|
+
|
113
113
|
end
|
114
114
|
|
115
115
|
end
|
116
|
-
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stewart McKee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mock_redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: spork
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: redis
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +81,7 @@ dependencies:
|
|
39
81
|
- !ruby/object:Gem::Version
|
40
82
|
version: '0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
84
|
+
name: redis-namespace
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
87
|
- - ">="
|
@@ -143,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
185
|
version: '0'
|
144
186
|
requirements: []
|
145
187
|
rubyforge_project: coffee_table
|
146
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.6.12
|
147
189
|
signing_key:
|
148
190
|
specification_version: 4
|
149
191
|
summary: Gem to manage cache stored in redis
|