coffee_table 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coffee_table.rb +23 -21
- data/lib/coffee_table/key.rb +4 -1
- data/lib/coffee_table/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cb5c9e9f996f2b3eb05c490f33c7354ff26836a
|
4
|
+
data.tar.gz: 9225f27d155e088628f766272b3ab5f664a2b38b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40872384ec30a13e2c964c39e7bd374aa15471db0b2cfdb4649655d52129d4d2629b3e1494fe70863c8f4fb98740a66c44054bb3b4bdc9e3c2e8de52663d9c2e
|
7
|
+
data.tar.gz: c8f33be7b34a580d83298bc9c887511550f7767e0fe18c41053d2898a4451fa1e3eb8980ad670bc46daa9393d45f68db3ad0c48fb1d05fb58d7fcdb6be459073
|
data/lib/coffee_table.rb
CHANGED
@@ -71,37 +71,39 @@ module CoffeeTable
|
|
71
71
|
|
72
72
|
# if first related_object is integer or fixnum it is used as an expiry time for the cache object
|
73
73
|
key = CoffeeTable::Key.new(initial_key, block_key, flags, related_objects)
|
74
|
-
|
75
74
|
if @options[:enable_cache]
|
76
75
|
if options.has_key?(:expiry)
|
77
76
|
expiry = options[:expiry]
|
78
77
|
else
|
79
78
|
expiry = nil
|
80
79
|
end
|
81
|
-
|
82
|
-
@redis.sadd "cache_keys", key unless @redis.sismember "cache_keys", key.to_s
|
83
80
|
if @redis.exists(key.to_s)
|
84
|
-
|
85
|
-
result = marshal_value(@redis.get(key.to_s).gunzip)
|
86
|
-
else
|
87
|
-
result = marshal_value(@redis.get(key.to_s))
|
88
|
-
end
|
81
|
+
result = marshal_value(@redis.get(key.to_s))
|
89
82
|
else
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
if compress_result
|
95
|
-
key.add_flag(:compressed => true)
|
96
|
-
@redis.set key.to_s, Marshal.dump(result.gzip)
|
83
|
+
key.add_flag(:compressed => true)
|
84
|
+
if @redis.exists(key.to_s)
|
85
|
+
result = marshal_value(@redis.get(key.to_s)).gunzip
|
97
86
|
else
|
98
|
-
|
99
|
-
|
87
|
+
key.remove_flag(:compressed)
|
88
|
+
result = yield
|
89
|
+
|
90
|
+
compress_result = @options[:compress_content] && result.kind_of?(String) && result.length > @options[:compress_min_size]
|
91
|
+
|
92
|
+
if compress_result
|
93
|
+
key.add_flag(:compressed => true)
|
94
|
+
@redis.sadd "cache_keys", key.to_s
|
95
|
+
@redis.set(key.to_s, Marshal.dump(result.gzip))
|
96
|
+
else
|
97
|
+
@redis.sadd "cache_keys", key.to_s
|
98
|
+
@redis.set(key.to_s, Marshal.dump(result))
|
99
|
+
end
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
unless expiry.nil?
|
102
|
+
@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
|
105
107
|
end
|
106
108
|
end
|
107
109
|
end
|
data/lib/coffee_table/key.rb
CHANGED
data/lib/coffee_table/version.rb
CHANGED
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stewart McKee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|