coffee_table 0.2.2 → 0.2.3

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: e8f7ff652cc590e6c9a33a97628fa5f7c97be1ac
4
- data.tar.gz: ee7d71355ae8cae5bbc822a7d8fb82c3a57e173c
3
+ metadata.gz: 85d61144259a5b7bed08d5f46414ed9aab9c3530
4
+ data.tar.gz: 4bd7ab36e8e1b5a917861200a6dd3d4abfc0f40a
5
5
  SHA512:
6
- metadata.gz: 289f04effa492d9d354f44bd624b6c65a3c7c9f7a7db502a540470a3978046587ea59692d6f49d979450a545e0a80a2d621dec469e62b069b090e78a493572fb
7
- data.tar.gz: 7dff15d4cd9c9a800c1349947dbcbeb56fc85257723955c918ff7e27e36c37ac3f154b7f8475824145e1900b4a0c5ad743b64f3e25941cc170a4aaf10fc0e886
6
+ metadata.gz: f6507d5dc3b338e5a25ca952a4add6487ccfb4d7ece8c689a46f9ade13d5241ce4b7c835fbfdbba051b0eb93cf568550eaa792fa741580f30ac76efeb0ceeef2
7
+ data.tar.gz: 65e52ce8da9becd35e3cef824c1b4e8fef0594bd230a53154e47418e790998afef30b972a6724bdef155e3a8525d3441451067fdc91cb96f431d835f5555a70d
@@ -1,3 +1,6 @@
1
+ 0.2.3
2
+ - closing redis connections on use
3
+
1
4
  0.2.2
2
5
  - added max_threads option due to limited thread environment in heroku
3
6
 
@@ -29,11 +29,6 @@ module CoffeeTable
29
29
  default_compress_min_size_to 10240
30
30
  default_max_threads_to 28
31
31
 
32
- if @options.has_key?(:redis_url)
33
- @redis = Redis.new({:url => @options[:redis_url]})
34
- else
35
- @redis = Redis.new({:server => @options[:redis_server], :port => @options[:redis_port]})
36
- end
37
32
  rufus_version = Gem::Version.new(Rufus::Scheduler::VERSION)
38
33
  if rufus_version >= Gem::Version.new('3.0.0')
39
34
  @scheduler = Rufus::Scheduler.new(:max_work_threads => @options[:max_threads])
@@ -42,10 +37,11 @@ module CoffeeTable
42
37
  end
43
38
  end
44
39
 
45
-
46
40
  def fetch(initial_key, *related_objects, &block)
47
41
  raise CoffeeTable::BlockMissingError, "No block given to generate cache from" unless block_given?
48
42
 
43
+ @redis = get_redis
44
+
49
45
  # extract the options hash if it is present
50
46
  options = {}
51
47
  if related_objects[-1].instance_of? Hash
@@ -105,14 +101,18 @@ module CoffeeTable
105
101
  else
106
102
  result = yield
107
103
  end
104
+
105
+ @redis.close
108
106
  result
109
107
  end
110
108
 
111
109
  def expire_key(key_value)
110
+ @redis = get_redis
112
111
  keys.map{|k| CoffeeTable::Key.parse(k)}.select{|key| key.has_element?(key_value) || key.to_s == key_value }.each do |key|
113
112
  @redis.del(key.to_s)
114
113
  @redis.srem "cache_keys", key.to_s
115
114
  end
115
+ @redis.close
116
116
  end
117
117
 
118
118
  def expire_all
@@ -120,7 +120,10 @@ module CoffeeTable
120
120
  end
121
121
 
122
122
  def keys
123
- @redis.smembers("cache_keys")
123
+ @redis = get_redis
124
+ members = @redis.smembers("cache_keys")
125
+ @redis.close
126
+ memberss
124
127
  end
125
128
 
126
129
  def expire_for(*objects)
@@ -180,5 +183,12 @@ module CoffeeTable
180
183
  def object_valid?(o)
181
184
  o.respond_to?(:id) || o.class == Class
182
185
  end
186
+ def get_redis
187
+ if @options.has_key?(:redis_url)
188
+ return Redis.new({:url => @options[:redis_url]})
189
+ else
190
+ return Redis.new({:server => @options[:redis_server], :port => @options[:redis_port]})
191
+ end
192
+ end
183
193
  end
184
194
  end
@@ -1,3 +1,3 @@
1
1
  module CoffeeTable
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
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.2
4
+ version: 0.2.3
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-06-01 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec