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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9188a9c93433bdb8536b896596edddc849ea371
4
- data.tar.gz: 5ffe54d715027e0a9f6211f3d4690c77387791d1
3
+ metadata.gz: 4cb5c9e9f996f2b3eb05c490f33c7354ff26836a
4
+ data.tar.gz: 9225f27d155e088628f766272b3ab5f664a2b38b
5
5
  SHA512:
6
- metadata.gz: d2b0db9cc4204fab712e20bbe3033018bf7d952d3d0bd1ab8c51b2b21c8f48b5107185627051f832523d1b93783d6c030cd2be54efca10e1309329b3aa1dcc50
7
- data.tar.gz: 8a4af84563f560560566e74e678a517fa7ffad8ee4ae2502e433e8469366d86833e5caa6ef8e82bee1b2ed8706fb1809454a7ff08096c1b8d904dd21cc44d294
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
- if key.options[:compressed]
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
- result = yield
91
-
92
- compress_result = @options[:compress_content] && result.kind_of?(String) && result.length > @options[:compress_min_size]
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
- @redis.set key.to_s, Marshal.dump(result)
99
- end
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
- unless expiry.nil?
102
- @redis.expire key.to_s, expiry
103
- @scheduler.in "#{expiry}s" do
104
- @redis.srem "cache_keys", key.to_s
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
@@ -41,6 +41,9 @@ module CoffeeTable
41
41
  def add_flag(options)
42
42
  @options.merge!(options)
43
43
  end
44
+ def remove_flag(key)
45
+ @options.delete key
46
+ end
44
47
 
45
48
  def elements
46
49
  @elements
@@ -88,4 +91,4 @@ module CoffeeTable
88
91
  end
89
92
  end
90
93
  end
91
- end
94
+ end
@@ -1,3 +1,3 @@
1
1
  module CoffeeTable
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  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.6
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: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec