iron_cache 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +6 -6
- data/lib/active_support/cache/iron_cache_store.rb +100 -0
- data/lib/iron_cache/caches.rb +4 -0
- data/lib/iron_cache/client.rb +1 -1
- data/lib/iron_cache/version.rb +1 -1
- data/test/load_er_up.rb +57 -0
- data/test/quick_run.rb +14 -7
- data/test/test_iron_cache.rb +18 -18
- metadata +5 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iron_cache (1.2.
|
4
|
+
iron_cache (1.2.1)
|
5
5
|
iron_core (>= 0.4.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
iron_core (0.4.
|
10
|
+
iron_core (0.4.3)
|
11
11
|
rest (>= 2.0.2)
|
12
12
|
memcache-client (1.8.5)
|
13
13
|
mime-types (1.19)
|
14
|
-
minitest (
|
14
|
+
minitest (4.1.0)
|
15
15
|
net-http-persistent (2.7)
|
16
16
|
rake (0.9.2.2)
|
17
|
-
rest (2.0.
|
17
|
+
rest (2.0.4)
|
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.
|
23
|
-
uber_config (
|
22
|
+
test-unit (2.5.2)
|
23
|
+
uber_config (1.0.5)
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
ruby
|
@@ -0,0 +1,100 @@
|
|
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).value
|
35
|
+
end
|
36
|
+
|
37
|
+
deserialize_entry(item)
|
38
|
+
end
|
39
|
+
|
40
|
+
def write_entry(key, entry, options)
|
41
|
+
with_namespace(key, options) do |cache, k|
|
42
|
+
cache.put(k, serialize_entry(entry, options), options)
|
43
|
+
end
|
44
|
+
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_entry(key, options)
|
49
|
+
with_namespace(key, options) do |cache, k|
|
50
|
+
cache.delete(k)
|
51
|
+
end
|
52
|
+
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def with_namespace(key, options)
|
59
|
+
options[:namespace] ||= 'rails_cache'
|
60
|
+
|
61
|
+
cache_name, key_name = namespaced_key(key, options).split(':', 2)
|
62
|
+
|
63
|
+
yield(@client.cache(cache_name), escape_key(key_name))
|
64
|
+
end
|
65
|
+
|
66
|
+
def escape_key(key)
|
67
|
+
ekey = ::Base64.encode64(key)
|
68
|
+
|
69
|
+
if ekey.size > 250
|
70
|
+
ekey = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}"
|
71
|
+
end
|
72
|
+
|
73
|
+
ekey
|
74
|
+
end
|
75
|
+
|
76
|
+
def deserialize_entry(raw_value)
|
77
|
+
if raw_value
|
78
|
+
entry = Marshal.load(raw_value) rescue raw_value
|
79
|
+
entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry)
|
80
|
+
else
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def serialize_entry(entry, options)
|
86
|
+
value = nil
|
87
|
+
|
88
|
+
if options[:raw]
|
89
|
+
if entry.respond_to?(:value)
|
90
|
+
value = entry.value.to_s
|
91
|
+
else
|
92
|
+
value = entry.to_s
|
93
|
+
end
|
94
|
+
else
|
95
|
+
value = Marshal.dump(entry)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/iron_cache/caches.rb
CHANGED
data/lib/iron_cache/client.rb
CHANGED
@@ -17,7 +17,7 @@ module IronCache
|
|
17
17
|
:host => IronCache::Client::AWS_US_EAST_HOST,
|
18
18
|
:port => 443,
|
19
19
|
:api_version => 1,
|
20
|
-
:user_agent => '
|
20
|
+
:user_agent => 'iron_cache_ruby-' + IronCache::VERSION + ' (iron_core_ruby-' + IronCore.version + ')',
|
21
21
|
:cache_name => 'default'
|
22
22
|
}
|
23
23
|
|
data/lib/iron_cache/version.rb
CHANGED
data/test/load_er_up.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
|
3
|
+
class QuickRun < TestBase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
#def test_loader
|
10
|
+
# cache_name = 'ironcache-load'
|
11
|
+
# cache = @client.cache(cache_name)
|
12
|
+
# p cache
|
13
|
+
# 100.times do |i|
|
14
|
+
# p i
|
15
|
+
# key = "x"
|
16
|
+
# value = "hello world!"
|
17
|
+
# res = cache.put(key, value)
|
18
|
+
# p res
|
19
|
+
# assert res.msg
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# cache.reload
|
23
|
+
# puts "size: #{cache.size}"
|
24
|
+
# assert_equal 100, cache.size
|
25
|
+
#
|
26
|
+
#end
|
27
|
+
|
28
|
+
def test_unloader
|
29
|
+
cache_name = 'ironcache-load'
|
30
|
+
cache = @client.cache(cache_name)
|
31
|
+
p cache
|
32
|
+
assert_equal 201, cache.size
|
33
|
+
res = cache.get("x")
|
34
|
+
p res
|
35
|
+
value = "hello world!"
|
36
|
+
assert_equal value, res.value
|
37
|
+
|
38
|
+
100.times do |i|
|
39
|
+
p i
|
40
|
+
key = "x#{i}"
|
41
|
+
res = cache.put(key, value)
|
42
|
+
#p res
|
43
|
+
assert res.msg
|
44
|
+
end
|
45
|
+
|
46
|
+
cache.reload
|
47
|
+
puts "size: #{cache.size}"
|
48
|
+
assert_equal 201, cache.size
|
49
|
+
|
50
|
+
res = cache.put("randomyo", value)
|
51
|
+
assert_equal 202, cache.reload.size
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
data/test/quick_run.rb
CHANGED
@@ -4,29 +4,36 @@ class QuickRun < TestBase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
super
|
7
|
-
@client.cache_name = 'ironcache-gem-quick'
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_basics
|
10
|
+
cache_name = 'ironcache-gem-quick'
|
11
|
+
cache = @client.cache(cache_name)
|
12
|
+
p cache
|
11
13
|
key = "x"
|
12
14
|
value = "hello world!"
|
13
|
-
res =
|
15
|
+
res = cache.put(key, value)
|
14
16
|
p res
|
15
17
|
assert res.msg
|
18
|
+
puts "size: #{cache.size}"
|
19
|
+
assert_equal 1, cache.size
|
16
20
|
|
17
|
-
res =
|
18
|
-
assert res.value
|
19
|
-
assert res.value == value
|
21
|
+
res = cache.get(key)
|
20
22
|
p res
|
23
|
+
assert_equal value, res.value
|
21
24
|
|
22
|
-
res =
|
25
|
+
res = cache.delete(key)
|
23
26
|
p res
|
24
27
|
assert res.msg
|
25
28
|
|
26
|
-
res =
|
29
|
+
res = cache.get(key)
|
27
30
|
p res
|
28
31
|
assert res.nil?
|
29
32
|
|
33
|
+
cache.reload
|
34
|
+
puts "size: #{cache.size}"
|
35
|
+
assert_equal 0, cache.size
|
36
|
+
|
30
37
|
end
|
31
38
|
|
32
39
|
|
data/test/test_iron_cache.rb
CHANGED
@@ -24,15 +24,15 @@ class IronCacheTests < TestBase
|
|
24
24
|
p res
|
25
25
|
assert res["key"]
|
26
26
|
assert res.key
|
27
|
-
|
28
|
-
|
27
|
+
assert_equal k, res.key
|
28
|
+
assert_equal v, res.value
|
29
29
|
|
30
30
|
res = @client.items.delete(res.key)
|
31
31
|
p res
|
32
32
|
puts "shouldn't be any more"
|
33
33
|
res = @client.items.get(k)
|
34
34
|
p res
|
35
|
-
|
35
|
+
assert_nil res
|
36
36
|
|
37
37
|
# new style of referencing cache
|
38
38
|
cache = @client.cache("test_basics")
|
@@ -44,15 +44,15 @@ class IronCacheTests < TestBase
|
|
44
44
|
p res
|
45
45
|
assert res["key"]
|
46
46
|
assert res.key
|
47
|
-
|
48
|
-
|
47
|
+
assert_equal k, res.key
|
48
|
+
assert_equal v, res.value
|
49
49
|
|
50
50
|
res = cache.delete(k)
|
51
51
|
p res
|
52
52
|
puts "shouldn't be any more"
|
53
53
|
res = cache.get(k)
|
54
54
|
p res
|
55
|
-
|
55
|
+
assert_nil res
|
56
56
|
|
57
57
|
# test delete by item
|
58
58
|
res = cache.put(k, v)
|
@@ -67,7 +67,7 @@ class IronCacheTests < TestBase
|
|
67
67
|
puts "shouldn't be any more"
|
68
68
|
res = cache.get(k)
|
69
69
|
p res
|
70
|
-
|
70
|
+
assert_nil res
|
71
71
|
|
72
72
|
|
73
73
|
# different cache names
|
@@ -112,11 +112,11 @@ class IronCacheTests < TestBase
|
|
112
112
|
|
113
113
|
res = @client.items.get(k)
|
114
114
|
p res
|
115
|
-
|
115
|
+
assert_equal k, res.key
|
116
116
|
|
117
117
|
sleep 11
|
118
118
|
res = @client.items.get(k)
|
119
|
-
|
119
|
+
assert_nil res
|
120
120
|
|
121
121
|
end
|
122
122
|
|
@@ -130,16 +130,16 @@ class IronCacheTests < TestBase
|
|
130
130
|
|
131
131
|
res = @client.items.get(k)
|
132
132
|
p res
|
133
|
-
|
134
|
-
|
133
|
+
assert_equal k, res.key
|
134
|
+
assert_equal v, res.value
|
135
135
|
|
136
136
|
incr_by = 10
|
137
137
|
res = @client.items.increment(k, incr_by)
|
138
138
|
res = @client.items.get(k)
|
139
|
-
|
139
|
+
assert_equal v + incr_by, res.value
|
140
140
|
|
141
141
|
res = @client.items.increment(k, -6)
|
142
|
-
|
142
|
+
assert_equal 5, res.value
|
143
143
|
|
144
144
|
res.delete
|
145
145
|
|
@@ -150,16 +150,16 @@ class IronCacheTests < TestBase
|
|
150
150
|
|
151
151
|
res = cache.get(k)
|
152
152
|
p res
|
153
|
-
|
154
|
-
|
153
|
+
assert_equal k, res.key
|
154
|
+
assert_equal v, res.value
|
155
155
|
|
156
156
|
incr_by = 10
|
157
157
|
res = cache.increment(k, incr_by)
|
158
158
|
res = cache.get(k)
|
159
|
-
|
159
|
+
assert_equal v + incr_by, res.value
|
160
160
|
|
161
161
|
res = cache.increment(k, -6)
|
162
|
-
|
162
|
+
assert_equal 5, res.value
|
163
163
|
|
164
164
|
res.delete
|
165
165
|
end
|
@@ -173,7 +173,7 @@ class IronCacheTests < TestBase
|
|
173
173
|
end
|
174
174
|
|
175
175
|
puts "cache.size: #{cache.size}"
|
176
|
-
|
176
|
+
assert_equal num_items, cache.size
|
177
177
|
end
|
178
178
|
|
179
179
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: iron_core
|
@@ -120,11 +120,13 @@ files:
|
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
122
|
- iron_cache.gemspec
|
123
|
+
- lib/active_support/cache/iron_cache_store.rb
|
123
124
|
- lib/iron_cache.rb
|
124
125
|
- lib/iron_cache/caches.rb
|
125
126
|
- lib/iron_cache/client.rb
|
126
127
|
- lib/iron_cache/items.rb
|
127
128
|
- lib/iron_cache/version.rb
|
129
|
+
- test/load_er_up.rb
|
128
130
|
- test/quick_run.rb
|
129
131
|
- test/test_base.rb
|
130
132
|
- test/test_iron_cache.rb
|
@@ -156,6 +158,7 @@ signing_key:
|
|
156
158
|
specification_version: 3
|
157
159
|
summary: Ruby client for IronCache by www.iron.io
|
158
160
|
test_files:
|
161
|
+
- test/load_er_up.rb
|
159
162
|
- test/quick_run.rb
|
160
163
|
- test/test_base.rb
|
161
164
|
- test/test_iron_cache.rb
|