iron_cache 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c8dd8df9e783faf82960cf94653ea10753b5b9d
4
+ data.tar.gz: 80af4020ad491ffd0ae3c5dfc088ec0bed62e6ac
5
+ SHA512:
6
+ metadata.gz: 5e9075944819698e6e33b9a3a6e5c0044ed8f83f24d09b12357049bb6da49e8658c3ba2affa1160bffb6190a95defbcf422b450bb891522f425222a68c1beb7b
7
+ data.tar.gz: 46990545a9c707d19c9020ed6796841a35b3307f1caa5e36a14fb2ddead9699ba279285e4c9c0e7604b2aa66d314b8d27db847bfe2cb55d2dbb89962248d51e1
data/.gitignore CHANGED
@@ -5,3 +5,5 @@ doc
5
5
  log
6
6
  test/config.yml
7
7
  *.sublime*
8
+ iron.json
9
+ config.yml
data/Gemfile.lock CHANGED
@@ -7,20 +7,20 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- iron_core (0.5.1)
11
- rest (>= 2.2.0)
10
+ iron_core (1.0.2)
11
+ rest (>= 2.6.4)
12
12
  memcache-client (1.8.5)
13
- mime-types (1.19)
14
- minitest (4.4.0)
15
- net-http-persistent (2.8)
16
- rake (10.0.3)
17
- rest (2.2.0)
13
+ mime-types (2.0)
14
+ minitest (5.2.0)
15
+ net-http-persistent (2.9)
16
+ rake (10.1.0)
17
+ rest (2.6.5)
18
18
  net-http-persistent
19
19
  rest-client (>= 0.3.0)
20
20
  rest-client (1.6.7)
21
21
  mime-types (>= 1.16)
22
- test-unit (2.5.3)
23
- uber_config (1.0.5)
22
+ test-unit (2.5.5)
23
+ uber_config (1.1.0)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
@@ -12,7 +12,7 @@ module IronCache
12
12
  def path(options={})
13
13
  path = "projects/#{@client.project_id}/caches"
14
14
  if options[:name]
15
- path << "/#{CGI::escape(options[:name])}"
15
+ path << "/#{CGI::escape(options[:name]).gsub('+', '%20')}"
16
16
  end
17
17
  path
18
18
  end
@@ -10,7 +10,7 @@ module IronCache
10
10
  end
11
11
 
12
12
  def path(key, options={})
13
- path = "projects/#{@client.project_id}/caches/#{CGI::escape(options[:cache_name] || @client.cache_name)}/items/#{CGI::escape(key)}#{'/increment' if options[:increment] == true}"
13
+ path = "projects/#{@client.project_id}/caches/#{CGI::escape(options[:cache_name] || @client.cache_name).gsub('+', '%20')}/items/#{CGI::escape(key).gsub('+', '%20')}#{'/increment' if options[:increment] == true}"
14
14
  end
15
15
 
16
16
  # options:
@@ -1,3 +1,3 @@
1
1
  module IronCache
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
data/test/load_er_up.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'test_base'
1
+ require File.expand_path('test_base.rb', File.dirname(__FILE__))
2
2
 
3
3
  class QuickRun < TestBase
4
4
 
data/test/quick_run.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'test_base'
1
+ require File.expand_path('test_base.rb', File.dirname(__FILE__))
2
2
 
3
3
  class QuickRun < TestBase
4
4
 
data/test/test_base.rb CHANGED
@@ -22,32 +22,41 @@ class TestBase < Test::Unit::TestCase
22
22
  def setup
23
23
  puts 'setup'
24
24
  # check multiple config locations
25
- @config = UberConfig.load
26
- puts "config=" + @config.inspect
27
- @client = IronCache::Client.new(@config['iron'])
25
+ begin
26
+ @config = UberConfig.load
27
+ puts "config=" + @config.inspect
28
+ @client = IronCache::Client.new(@config['iron'])
29
+ rescue => ex
30
+ puts "UberConfig couldn't find file, trying normal Iron.io config..."
31
+ @client = IronCache::Client.new
32
+ end
33
+
28
34
  @client.logger.level = Logger::DEBUG
29
35
  @client.cache_name = 'iron_cache_ruby_tests'
30
36
 
31
37
  end
32
38
 
33
- def clear_queue(queue_name=nil)
34
- #queue_name ||= @client.cache_name
35
- #puts "clearing queue #{queue_name}"
36
- #while res = @client.messages.get(:cache_name=>queue_name)
37
- # p res
38
- # puts res.body.to_s
39
- # res.delete
40
- #end
41
- #puts 'cleared.'
39
+ def clear_cache(cache_name=nil)
40
+ cache_name ||= @client.cache_name
41
+ puts "clearing cache #{cache_name}"
42
+ cache = @client.cache(cache_name)
43
+ begin
44
+ cache.clear
45
+ puts 'cleared.'
46
+ rescue Rest::HttpError => ex
47
+ unless ex.code == 404
48
+ raise ex
49
+ end
50
+ end
51
+
42
52
  end
43
53
 
44
54
  def assert_performance(time)
45
55
  start_time = Time.now
46
56
  yield
47
- execution_time = Time.now - start_time
57
+ execution_time = Time.now - start_time
48
58
  assert execution_time < time, "Execution time too big #{execution_time.round(2)}, should be #{time}"
49
59
  end
50
60
 
51
61
 
52
-
53
62
  end
@@ -0,0 +1,23 @@
1
+ require 'test/unit'
2
+ require 'yaml'
3
+ require File.expand_path('test_base.rb', File.dirname(__FILE__))
4
+
5
+ class IronCacheTests < TestBase
6
+ def setup
7
+ super
8
+ end
9
+
10
+ def test_basics
11
+ @client.cache_name = 'test_errors'
12
+ clear_cache
13
+
14
+ k = "key1"
15
+ v = "hello world!"
16
+
17
+ res = @client.items.get(k)
18
+ p res
19
+
20
+ end
21
+
22
+ end
23
+
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'yaml'
3
- require 'test_base'
3
+ require File.expand_path('test_base.rb', File.dirname(__FILE__))
4
4
 
5
5
  class IronCacheTests < TestBase
6
6
  def setup
@@ -9,7 +9,7 @@ class IronCacheTests < TestBase
9
9
 
10
10
  def test_basics
11
11
  @client.cache_name = 'test_basics'
12
- clear_queue
12
+ clear_cache
13
13
 
14
14
  k = "key1"
15
15
  v = "hello world!"
@@ -104,7 +104,7 @@ class IronCacheTests < TestBase
104
104
 
105
105
  def test_expiry
106
106
  @client.cache_name = 'test_basics'
107
- clear_queue
107
+ clear_cache
108
108
  k = "key1"
109
109
  v = "hello world!"
110
110
  res = @client.items.put(k, v, :expires_in => 10)
@@ -121,7 +121,7 @@ class IronCacheTests < TestBase
121
121
 
122
122
  def test_incrementors
123
123
  @client.cache_name = 'test_incrementors'
124
- clear_queue
124
+ clear_cache
125
125
  k = "incr1"
126
126
  v = 1
127
127
  res = @client.items.put(k, v)
@@ -178,7 +178,7 @@ class IronCacheTests < TestBase
178
178
 
179
179
  def test_keys
180
180
  @client.cache_name = 'test_keys'
181
- clear_queue
181
+ clear_cache
182
182
 
183
183
  k = "word_count_[EBook"
184
184
  v = "hello world!"
@@ -193,6 +193,8 @@ class IronCacheTests < TestBase
193
193
 
194
194
  def test_clear
195
195
  cache = @client.cache("test_clear_3")
196
+ clear_cache(cache.name)
197
+
196
198
  num_items = 50
197
199
 
198
200
  num_items.times do |i|
@@ -201,6 +203,8 @@ class IronCacheTests < TestBase
201
203
 
202
204
  tkey = "key-0"
203
205
  assert_equal "value", cache.get(tkey).value
206
+
207
+ cache.reload
204
208
  puts "cache.size: #{cache.size}"
205
209
  assert_equal num_items, cache.size
206
210
 
@@ -210,5 +214,26 @@ class IronCacheTests < TestBase
210
214
  assert_equal 0, cache.reload.size
211
215
  end
212
216
 
217
+ def test_add
218
+ cache = @client.cache("test_add")
219
+ cache.clear rescue ""
220
+ udq_expires = 60 # 1 min
221
+ k = 'mykey'
222
+ r = cache.put(k, 0, :expires_in => udq_expires)
223
+ r = cache.increment(k)
224
+ p r
225
+ assert_equal 1, r.value
226
+ cache.put(k, 0, :add => true, :expires_in => udq_expires)
227
+ p r
228
+ r = cache.increment(k)
229
+ p r
230
+ assert_equal 2, r.value
231
+ cache.put(k, 0, :add => true, :expires_in => udq_expires)
232
+ r = cache.increment(k)
233
+ p r
234
+ assert_equal 3, r.value, "value is #{r.value}, expected 3"
235
+ end
236
+
237
+
213
238
  end
214
239
 
@@ -1,7 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'yaml'
3
3
  require 'memcache'
4
- require 'test_base'
4
+ require File.expand_path('test_base.rb', File.dirname(__FILE__))
5
5
 
6
6
  class IronCacheMemcachedTests < TestBase
7
7
  def setup
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'yaml'
3
- require 'test_base'
3
+ require File.expand_path('test_base.rb', File.dirname(__FILE__))
4
4
 
5
5
  class TestPerformance < TestBase
6
6
  def setup
data/test/tmp.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'yaml'
3
- require 'test_base'
3
+ require File.expand_path('test_base.rb', File.dirname(__FILE__))
4
4
 
5
5
  class IronCacheTests < TestBase
6
6
  def setup
@@ -8,23 +8,5 @@ class IronCacheTests < TestBase
8
8
  end
9
9
 
10
10
 
11
- def test_clear
12
- cache = @client.cache("test_clear")
13
- num_items = 50
14
-
15
- num_items.times do |i|
16
- res = cache.put("key-#{i}", "value")
17
- end
18
-
19
- tkey = "key-0"
20
- assert_equal "value", cache.get(tkey).value
21
- puts "cache.size: #{cache.size}"
22
- assert_equal num_items, cache.size
23
-
24
- p cache.clear
25
- assert_nil cache.get(tkey)
26
- assert_equal 0, cache.reload.size
27
- end
28
-
29
11
  end
30
12
 
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
5
- prerelease:
4
+ version: 1.4.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Travis Reeder
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: iron_core
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.5.1
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.5.1
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: test-unit
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: memcache-client
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: uber_config
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: Ruby client for IronCache by www.iron.io
@@ -120,8 +107,6 @@ files:
120
107
  - README.md
121
108
  - Rakefile
122
109
  - iron_cache.gemspec
123
- - lib/action_dispatch/session/iron_cache.rb
124
- - lib/active_support/cache/iron_cache_store.rb
125
110
  - lib/iron_cache.rb
126
111
  - lib/iron_cache/caches.rb
127
112
  - lib/iron_cache/client.rb
@@ -130,38 +115,39 @@ files:
130
115
  - test/load_er_up.rb
131
116
  - test/quick_run.rb
132
117
  - test/test_base.rb
118
+ - test/test_errors.rb
133
119
  - test/test_iron_cache.rb
134
120
  - test/test_memcached.rb
135
121
  - test/test_performance.rb
136
122
  - test/tmp.rb
137
123
  homepage: https://github.com/iron-io/iron_cache_ruby
138
124
  licenses: []
125
+ metadata: {}
139
126
  post_install_message:
140
127
  rdoc_options: []
141
128
  require_paths:
142
129
  - lib
143
130
  required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
131
  requirements:
146
- - - ! '>='
132
+ - - '>='
147
133
  - !ruby/object:Gem::Version
148
134
  version: '1.8'
149
135
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
136
  requirements:
152
- - - ! '>='
137
+ - - '>='
153
138
  - !ruby/object:Gem::Version
154
139
  version: 1.3.6
155
140
  requirements: []
156
141
  rubyforge_project:
157
- rubygems_version: 1.8.24
142
+ rubygems_version: 2.0.3
158
143
  signing_key:
159
- specification_version: 3
144
+ specification_version: 4
160
145
  summary: Ruby client for IronCache by www.iron.io
161
146
  test_files:
162
147
  - test/load_er_up.rb
163
148
  - test/quick_run.rb
164
149
  - test/test_base.rb
150
+ - test/test_errors.rb
165
151
  - test/test_iron_cache.rb
166
152
  - test/test_memcached.rb
167
153
  - test/test_performance.rb
@@ -1,93 +0,0 @@
1
- require 'iron_cache'
2
- require 'base64'
3
- require 'action_dispatch/middleware/session/abstract_store'
4
-
5
- module ActionDispatch
6
- module Session
7
- class IronCache < ActionDispatch::Session::AbstractStore
8
-
9
- def initialize(app, options = {})
10
- @options = options
11
- super
12
-
13
- @client = ::IronCache::Client.new(options)
14
- end
15
-
16
- def options
17
- @options
18
- end
19
-
20
- def get_session(env, session_id)
21
- item = nil
22
- session_id ||= generate_sid
23
-
24
- with_namespace(session_id, options) do |cache, k|
25
- item = cache.get(k)
26
- item = item.value unless item.nil?
27
- end
28
-
29
- session_data = deserialize_entry(item) rescue {}
30
-
31
- [session_id, session_data]
32
- end
33
-
34
- def set_session(env, session_id, session, options)
35
- with_namespace(session_id, options) do |cache, k|
36
- cache.put(k, serialize_entry(session, options), options)
37
- end
38
-
39
- session_id
40
- end
41
-
42
- def destroy_session(env, session_id, options)
43
- with_namespace(session_id, options) do |cache, k|
44
- cache.delete(k)
45
- end
46
-
47
- generate_sid
48
- end
49
-
50
- private
51
-
52
- def with_namespace(key, options)
53
- options[:namespace] ||= 'rails_cache'
54
-
55
- cache_name = options[:namespace]
56
-
57
- yield(@client.cache(cache_name), escape_key(key))
58
- end
59
-
60
- def escape_key(key)
61
- ekey = ::Base64.encode64(key)
62
-
63
- if ekey.size > 250
64
- ekey = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}"
65
- end
66
-
67
- ekey
68
- end
69
-
70
- def deserialize_entry(raw_value)
71
- if raw_value
72
- raw_value = ::Base64.decode64(raw_value) rescue raw_value
73
- Marshal.load(raw_value) rescue raw_value
74
- else
75
- nil
76
- end
77
- end
78
-
79
- def serialize_entry(entry, options)
80
- if options[:raw]
81
- if entry.respond_to?(:value)
82
- entry.value.to_s
83
- else
84
- entry.to_s
85
- end
86
- else
87
- ::Base64.encode64 Marshal.dump(entry)
88
- end
89
- end
90
-
91
- end
92
- end
93
- end
@@ -1,102 +0,0 @@
1
- require 'iron_cache'
2
- require 'base64'
3
-
4
- module ActiveSupport
5
- module Cache
6
- class IronCacheStore < ActiveSupport::Cache::Store
7
-
8
- def initialize(options = nil)
9
- super(options)
10
-
11
- @client = IronCache::Client.new(@options)
12
-
13
- extend ActiveSupport::Cache::Strategy::LocalCache
14
- end
15
-
16
- def increment(key, amount = 1, options = nil)
17
- with_namespace(key, options) do |cache, k|
18
- cache.increment(k, amount)
19
- end
20
- end
21
-
22
- def decrement(key, amount = 1, options = nil)
23
- with_namespace(key, options) do |cache, k|
24
- cache.increment(k, -amount)
25
- end
26
- end
27
-
28
- protected
29
-
30
- def read_entry(key, options)
31
- item = nil
32
-
33
- with_namespace(key, options) do |cache, k|
34
- item = cache.get(k)
35
- item = item.value unless item.nil?
36
- end
37
-
38
- deserialize_entry(item)
39
- end
40
-
41
- def write_entry(key, entry, options)
42
- with_namespace(key, options) do |cache, k|
43
- cache.put(k, serialize_entry(entry, options), options)
44
- end
45
-
46
- true
47
- end
48
-
49
- def delete_entry(key, options)
50
- with_namespace(key, options) do |cache, k|
51
- cache.delete(k)
52
- end
53
-
54
- true
55
- end
56
-
57
- private
58
-
59
- def with_namespace(key, options)
60
- options[:namespace] ||= 'rails_cache'
61
-
62
- cache_name, key_name = namespaced_key(key, options).split(':', 2)
63
-
64
- yield(@client.cache(cache_name), escape_key(key_name))
65
- end
66
-
67
- def escape_key(key)
68
- ekey = ::Base64.encode64(key)
69
-
70
- if ekey.size > 250
71
- ekey = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}"
72
- end
73
-
74
- ekey
75
- end
76
-
77
- def deserialize_entry(raw_value)
78
- if raw_value
79
- raw_value = ::Base64.decode64(raw_value) rescue raw_value
80
- entry = Marshal.load(raw_value) rescue raw_value
81
- entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry)
82
- else
83
- nil
84
- end
85
- end
86
-
87
- def serialize_entry(entry, options)
88
- value = nil
89
-
90
- if options[:raw]
91
- if entry.respond_to?(:value)
92
- value = entry.value.to_s
93
- else
94
- value = entry.to_s
95
- end
96
- else
97
- value = ::Base64.encode64 Marshal.dump(entry)
98
- end
99
- end
100
- end
101
- end
102
- end