iron_cache 1.3.0 → 1.4.0
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.
- data/Gemfile.lock +8 -8
- data/README.md +29 -1
- data/iron_cache.gemspec +2 -2
- data/lib/action_dispatch/session/iron_cache.rb +93 -0
- data/lib/iron_cache.rb +9 -4
- data/lib/iron_cache/items.rb +2 -2
- data/lib/iron_cache/version.rb +1 -1
- data/test/load_er_up.rb +1 -1
- data/test/quick_run.rb +1 -1
- data/test/test_base.rb +9 -1
- data/test/test_iron_cache.rb +3 -3
- data/test/test_memcached.rb +1 -2
- data/test/test_performance.rb +1 -2
- data/test/tmp.rb +1 -2
- metadata +6 -5
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iron_cache (1.
|
5
|
-
iron_core (>= 0.
|
4
|
+
iron_cache (1.4.0)
|
5
|
+
iron_core (>= 0.5.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
iron_core (0.
|
11
|
-
rest (>= 2.0
|
10
|
+
iron_core (0.5.1)
|
11
|
+
rest (>= 2.2.0)
|
12
12
|
memcache-client (1.8.5)
|
13
13
|
mime-types (1.19)
|
14
|
-
minitest (4.
|
14
|
+
minitest (4.4.0)
|
15
15
|
net-http-persistent (2.8)
|
16
|
-
rake (0.
|
17
|
-
rest (2.0
|
16
|
+
rake (10.0.3)
|
17
|
+
rest (2.2.0)
|
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.
|
22
|
+
test-unit (2.5.3)
|
23
23
|
uber_config (1.0.5)
|
24
24
|
|
25
25
|
PLATFORMS
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Getting Started
|
|
8
8
|
|
9
9
|
gem install iron_cache
|
10
10
|
|
11
|
-
2\. Setup your Iron.io credentials: http://dev.iron.io/
|
11
|
+
2\. Setup your Iron.io credentials: http://dev.iron.io/cache/reference/configuration/
|
12
12
|
|
13
13
|
3\. Create an IronCache client object:
|
14
14
|
|
@@ -44,6 +44,12 @@ Now you can use it:
|
|
44
44
|
msg = @cache.increment("mycounter", 1)
|
45
45
|
p res
|
46
46
|
|
47
|
+
For all the options for each of these methods, please see our [API docs](http://dev.iron.io/cache/reference/api/). Every option can be passed in
|
48
|
+
via an optional hash in the above methods, eg:
|
49
|
+
|
50
|
+
@cache.put("mykey", "hello world!", :expires_in=>3600)
|
51
|
+
|
52
|
+
|
47
53
|
Cache Information
|
48
54
|
=================
|
49
55
|
|
@@ -60,3 +66,25 @@ You can use IronCache as any other rails store. Put iron.json into your project'
|
|
60
66
|
Alternatively, you can supply project_id and token in code.
|
61
67
|
|
62
68
|
config.cache_store = :iron_cache_store, :project_id => 'XXX', :token => 'YYY'
|
69
|
+
|
70
|
+
|
71
|
+
Using As Rails Session Store
|
72
|
+
====================
|
73
|
+
|
74
|
+
You can use IronCache as any other rails session store. Put iron.json into your project's config dir, add iron_cache to Gemfile and you are ready to go.
|
75
|
+
|
76
|
+
`config/initializers/session_store.rb` :
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
AppName::Application.config.session_store :iron_cache_store
|
80
|
+
```
|
81
|
+
|
82
|
+
Alternatively, you can supply project_id and token in code.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
AppName::Application.config.session_store :iron_cache,
|
86
|
+
project_id: 'XXX',
|
87
|
+
token: 'YYY',
|
88
|
+
namespace: 'other-cache-name',
|
89
|
+
expires_in: 7200
|
90
|
+
```
|
data/iron_cache.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.version = IronCache::VERSION
|
16
16
|
|
17
17
|
gem.required_rubygems_version = ">= 1.3.6"
|
18
|
-
gem.required_ruby_version = Gem::Requirement.new(">= 1.
|
19
|
-
gem.add_runtime_dependency "iron_core", ">= 0.
|
18
|
+
gem.required_ruby_version = Gem::Requirement.new(">= 1.8")
|
19
|
+
gem.add_runtime_dependency "iron_core", ">= 0.5.1"
|
20
20
|
|
21
21
|
gem.add_development_dependency "test-unit"
|
22
22
|
gem.add_development_dependency "minitest"
|
@@ -0,0 +1,93 @@
|
|
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
|
data/lib/iron_cache.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'rest'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
require "iron_cache/version"
|
3
|
+
require 'iron_cache/caches'
|
4
|
+
require 'iron_cache/items'
|
5
|
+
require 'iron_cache/client'
|
6
|
+
|
7
|
+
# session store
|
8
|
+
if defined? ActionDispatch
|
9
|
+
require 'action_dispatch/session/iron_cache'
|
10
|
+
end
|
data/lib/iron_cache/items.rb
CHANGED
@@ -40,7 +40,7 @@ module IronCache
|
|
40
40
|
# :expires_in => After this delay in seconds, message will be automatically removed from the cache.
|
41
41
|
def put(key, value, options={})
|
42
42
|
to_send = options
|
43
|
-
to_send[:
|
43
|
+
to_send[:value] = value
|
44
44
|
res = @client.put(path(key, options), to_send)
|
45
45
|
json = @client.parse_response(res, true)
|
46
46
|
#return Message.new(self, res)
|
@@ -107,7 +107,7 @@ module IronCache
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def delete
|
110
|
-
@messages.delete(self.key, cache_name
|
110
|
+
@messages.delete(self.key, :cache_name => raw['cache'])
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
data/lib/iron_cache/version.rb
CHANGED
data/test/load_er_up.rb
CHANGED
data/test/quick_run.rb
CHANGED
data/test/test_base.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
3
|
require 'yaml'
|
4
4
|
require 'uber_config'
|
5
|
+
|
6
|
+
unless Hash.instance_methods.include?(:default_proc=)
|
7
|
+
class Hash
|
8
|
+
def default_proc=(proc)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
begin
|
6
14
|
require File.join(File.dirname(__FILE__), '../lib/iron_cache')
|
7
15
|
rescue Exception => ex
|
data/test/test_iron_cache.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
gem 'test-unit'
|
2
1
|
require 'test/unit'
|
3
2
|
require 'yaml'
|
4
|
-
|
3
|
+
require 'test_base'
|
5
4
|
|
6
5
|
class IronCacheTests < TestBase
|
7
6
|
def setup
|
@@ -193,7 +192,7 @@ class IronCacheTests < TestBase
|
|
193
192
|
|
194
193
|
|
195
194
|
def test_clear
|
196
|
-
cache = @client.cache("
|
195
|
+
cache = @client.cache("test_clear_3")
|
197
196
|
num_items = 50
|
198
197
|
|
199
198
|
num_items.times do |i|
|
@@ -206,6 +205,7 @@ class IronCacheTests < TestBase
|
|
206
205
|
assert_equal num_items, cache.size
|
207
206
|
|
208
207
|
p cache.clear
|
208
|
+
sleep 2
|
209
209
|
assert_nil cache.get(tkey)
|
210
210
|
assert_equal 0, cache.reload.size
|
211
211
|
end
|
data/test/test_memcached.rb
CHANGED
data/test/test_performance.rb
CHANGED
data/test/tmp.rb
CHANGED
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.
|
4
|
+
version: 1.4.0
|
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:
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: iron_core
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.5.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: 0.5.1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: test-unit
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
122
|
- iron_cache.gemspec
|
123
|
+
- lib/action_dispatch/session/iron_cache.rb
|
123
124
|
- lib/active_support/cache/iron_cache_store.rb
|
124
125
|
- lib/iron_cache.rb
|
125
126
|
- lib/iron_cache/caches.rb
|
@@ -144,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
145
|
requirements:
|
145
146
|
- - ! '>='
|
146
147
|
- !ruby/object:Gem::Version
|
147
|
-
version: '1.
|
148
|
+
version: '1.8'
|
148
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
150
|
none: false
|
150
151
|
requirements:
|