libmemcached_store 0.2.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +7 -0
- data/BENCHMARKS +37 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +78 -0
- data/Rakefile +24 -0
- data/gemfiles/rails30.gemfile +7 -0
- data/gemfiles/rails31.gemfile +7 -0
- data/gemfiles/rails32.gemfile +7 -0
- data/lib/action_dispatch/session/libmemcached_store.rb +80 -0
- data/lib/active_support/cache/libmemcached_store.rb +227 -81
- data/lib/libmemcached_store.rb +1 -1
- data/lib/memcached/get_with_flags.rb +42 -0
- data/lib/version.rb +3 -0
- data/libmemcached_store.gemspec +30 -0
- data/test/action_dispatch/abstract_unit.rb +43 -0
- data/test/action_dispatch/libmemcached_store_test.rb +200 -0
- data/test/active_support/libmemcached_store_test.rb +341 -0
- data/test/fixtures/session_autoload_test.rb +10 -0
- data/test/profile/benchmark.rb +94 -0
- data/test/test_helper.rb +5 -0
- metadata +132 -86
- data/README +0 -47
- data/lib/active_support/cache/compressed_libmemcached_store.rb +0 -15
- data/test/libmemcached_store_test.rb +0 -84
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
require 'libmemcached_store'
|
5
|
+
require 'active_support/cache/libmemcached_store'
|
6
|
+
|
7
|
+
require 'dalli'
|
8
|
+
require 'active_support/cache/dalli_store'
|
9
|
+
|
10
|
+
puts "Testing with"
|
11
|
+
puts RUBY_DESCRIPTION
|
12
|
+
puts "Dalli #{Dalli::VERSION}"
|
13
|
+
puts "Libmemcached_store #{LibmemcachedStore::VERSION}"
|
14
|
+
|
15
|
+
# We'll use a simple @value to try to avoid spending time in Marshal,
|
16
|
+
# which is a constant penalty that both clients have to pay
|
17
|
+
@value = []
|
18
|
+
@marshalled = Marshal.dump(@value)
|
19
|
+
|
20
|
+
@servers = ['127.0.0.1:11211']
|
21
|
+
@key1 = "Short"
|
22
|
+
@key2 = "Sym1-2-3::45"*4
|
23
|
+
@key3 = "Long"*40
|
24
|
+
@key4 = "Medium"*8
|
25
|
+
|
26
|
+
N = 2_500
|
27
|
+
|
28
|
+
@dalli = ActiveSupport::Cache::DalliStore.new(@servers).silence!
|
29
|
+
@libm = ActiveSupport::Cache::LibmemcachedStore.new(@servers).silence!
|
30
|
+
|
31
|
+
def clear
|
32
|
+
@dalli.clear
|
33
|
+
@libm.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_method(title, method_name, key, *arguments)
|
37
|
+
{ dalli: @dalli, libm: @libm }.each do |name, store|
|
38
|
+
@job.report("#{title}:#{name}") { N.times { store.send(method_name, key, *arguments) } }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_method(method_name, key, *arguments)
|
43
|
+
[@dalli, @libm].each do |store|
|
44
|
+
store.send(method_name, key, *arguments)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Benchmark.bm(31) do |x|
|
49
|
+
@job = x
|
50
|
+
|
51
|
+
test_method('write:short', :write, @key1, @value)
|
52
|
+
test_method('write:long', :write, @key3, @value)
|
53
|
+
test_method('write:raw', :write, @key4, @value, raw: true)
|
54
|
+
|
55
|
+
puts
|
56
|
+
clear
|
57
|
+
|
58
|
+
test_method('read:miss', :read, @key1)
|
59
|
+
test_method('read:miss2', :read, @key1)
|
60
|
+
|
61
|
+
run_method(:write, @key4, @value)
|
62
|
+
test_method('read:exist', :read, @key4)
|
63
|
+
|
64
|
+
run_method(:write, @key4, @value, expires_in: 1)
|
65
|
+
sleep(1)
|
66
|
+
test_method('read:expired', :read, @key2)
|
67
|
+
|
68
|
+
run_method(:write, @key3, @value, raw: true)
|
69
|
+
test_method('read:raw', :read, @key3, raw: true)
|
70
|
+
|
71
|
+
puts
|
72
|
+
clear
|
73
|
+
|
74
|
+
test_method('exist:miss', :exist?, @key4)
|
75
|
+
|
76
|
+
run_method(:write, @key4, @value)
|
77
|
+
test_method('exist:hit', :exist?, @key4)
|
78
|
+
|
79
|
+
puts
|
80
|
+
clear
|
81
|
+
|
82
|
+
test_method('delete:miss', :delete, @key4)
|
83
|
+
|
84
|
+
run_method(:write, @key1, @value)
|
85
|
+
test_method('delete:hit', :delete, @key1)
|
86
|
+
|
87
|
+
puts
|
88
|
+
clear
|
89
|
+
|
90
|
+
run_method(:write, @key4, 0, raw: true)
|
91
|
+
|
92
|
+
test_method('increment', :increment, @key4)
|
93
|
+
test_method('decrement', :decrement, @key4)
|
94
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,114 +1,160 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: libmemcached_store
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 3
|
10
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
7
|
+
- Christopher Cocchi-Perrier
|
8
|
+
- Ben Hutton
|
13
9
|
- Jeffrey Hardy
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: memcached
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rack
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
21
44
|
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
22
51
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: mocha
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
32
64
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: memcached
|
36
65
|
prerelease: false
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
46
|
-
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
49
72
|
name: activesupport
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3'
|
78
|
+
type: :development
|
50
79
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '3'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: actionpack
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '3'
|
62
99
|
description: |-
|
63
100
|
An ActiveSupport cache store that uses the C-based libmemcached client through
|
64
101
|
Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast, lightweight,
|
65
102
|
and supports consistent hashing, non-blocking IO, and graceful server failover.
|
66
|
-
email:
|
67
|
-
- packagethief@gmail.com
|
103
|
+
email: cocchi.c@gmail.com
|
68
104
|
executables: []
|
69
|
-
|
70
105
|
extensions: []
|
71
|
-
|
72
106
|
extra_rdoc_files: []
|
73
|
-
|
74
|
-
|
75
|
-
-
|
107
|
+
files:
|
108
|
+
- .gitignore
|
109
|
+
- .travis.yml
|
110
|
+
- BENCHMARKS
|
111
|
+
- CHANGELOG.md
|
112
|
+
- Gemfile
|
113
|
+
- MIT-LICENSE
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- gemfiles/rails30.gemfile
|
117
|
+
- gemfiles/rails31.gemfile
|
118
|
+
- gemfiles/rails32.gemfile
|
119
|
+
- lib/action_dispatch/session/libmemcached_store.rb
|
76
120
|
- lib/active_support/cache/libmemcached_store.rb
|
77
121
|
- lib/libmemcached_store.rb
|
78
|
-
-
|
79
|
-
-
|
80
|
-
|
122
|
+
- lib/memcached/get_with_flags.rb
|
123
|
+
- lib/version.rb
|
124
|
+
- libmemcached_store.gemspec
|
125
|
+
- test/action_dispatch/abstract_unit.rb
|
126
|
+
- test/action_dispatch/libmemcached_store_test.rb
|
127
|
+
- test/active_support/libmemcached_store_test.rb
|
128
|
+
- test/fixtures/session_autoload_test.rb
|
129
|
+
- test/profile/benchmark.rb
|
130
|
+
- test/test_helper.rb
|
131
|
+
homepage: http://github.com/ccocchi/libmemcached_store
|
81
132
|
licenses: []
|
82
|
-
|
133
|
+
metadata: {}
|
83
134
|
post_install_message:
|
84
135
|
rdoc_options: []
|
85
|
-
|
86
|
-
require_paths:
|
136
|
+
require_paths:
|
87
137
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
none: false
|
99
|
-
requirements:
|
100
|
-
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
hash: 3
|
103
|
-
segments:
|
104
|
-
- 0
|
105
|
-
version: "0"
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
106
148
|
requirements: []
|
107
|
-
|
108
149
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
150
|
+
rubygems_version: 2.0.0
|
110
151
|
signing_key:
|
111
|
-
specification_version:
|
112
|
-
summary: ActiveSupport
|
113
|
-
test_files:
|
114
|
-
- test/
|
152
|
+
specification_version: 4
|
153
|
+
summary: ActiveSupport 3+ cache store for the C-based libmemcached client
|
154
|
+
test_files:
|
155
|
+
- test/action_dispatch/abstract_unit.rb
|
156
|
+
- test/action_dispatch/libmemcached_store_test.rb
|
157
|
+
- test/active_support/libmemcached_store_test.rb
|
158
|
+
- test/fixtures/session_autoload_test.rb
|
159
|
+
- test/profile/benchmark.rb
|
160
|
+
- test/test_helper.rb
|
data/README
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
= LibmemcachedStore
|
2
|
-
|
3
|
-
An ActiveSupport cache store that uses the C-based libmemcached client through
|
4
|
-
Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast, lightweight,
|
5
|
-
and supports consistent hashing, non-blocking IO, and graceful server failover.
|
6
|
-
|
7
|
-
== Prerequisites
|
8
|
-
|
9
|
-
You'll need both the libmemcached client and the memcached gem:
|
10
|
-
|
11
|
-
* http://tangent.org/552/libmemcached.html
|
12
|
-
* http://blog.evanweaver.com/files/doc/fauna/memcached
|
13
|
-
|
14
|
-
Make sure you install libmemcached first, before you try installing the gem. If
|
15
|
-
you're using OS X, the easiest way to install libmemcached is through MacPorts:
|
16
|
-
|
17
|
-
sudo port install libmemcached
|
18
|
-
|
19
|
-
For other platforms, download and extract the libmemcached tarball and install
|
20
|
-
manually:
|
21
|
-
|
22
|
-
./configure
|
23
|
-
make && sudo make install
|
24
|
-
|
25
|
-
Once libmemcached is installed, install the memcached gem:
|
26
|
-
|
27
|
-
gem install memcached --no-rdoc --no-ri
|
28
|
-
|
29
|
-
== Usage
|
30
|
-
|
31
|
-
This is a drop-in replacement for the memcache store that ships with Rails. To
|
32
|
-
enable, set the <tt>config.cache_store</tt> option to <tt>:libmemcached_store</tt>
|
33
|
-
in the config for your environment
|
34
|
-
|
35
|
-
config.cache_store = :libmemcached_store
|
36
|
-
|
37
|
-
If no servers are specified, localhost is assumed. You can specify a list of
|
38
|
-
server addresses, either as hostnames or IP addresses, with or without a port
|
39
|
-
designation. If no port is given, 11211 is assumed:
|
40
|
-
|
41
|
-
config.cache_store = :libmemcached_store, %w(cache-01 cache-02 127.0.0.1:11212)
|
42
|
-
|
43
|
-
== Props
|
44
|
-
|
45
|
-
Thanks to Brian Aker (http://tangent.org) for creating libmemcached, and Evan
|
46
|
-
Weaver (http://blog.evanweaver.com) for the Ruby wrapper.
|
47
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
module Cache
|
3
|
-
class CompressedLibmemcachedStore < LibmemcachedStore
|
4
|
-
def read(name, options = {})
|
5
|
-
if value = super(name, (options || {}).merge(:raw => true))
|
6
|
-
Marshal.load(ActiveSupport::Gzip.decompress(value))
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def write(name, value, options = {})
|
11
|
-
super(name, ActiveSupport::Gzip.compress(Marshal.dump(value)), (options || {}).merge(:raw => true))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'active_support'
|
4
|
-
require 'memcached'
|
5
|
-
|
6
|
-
require File.dirname(__FILE__) + '/../lib/libmemcached_store'
|
7
|
-
|
8
|
-
# Make it easier to get at the underlying cache options during testing.
|
9
|
-
class ActiveSupport::Cache::LibmemcachedStore
|
10
|
-
delegate :options, :to => '@cache'
|
11
|
-
end
|
12
|
-
|
13
|
-
class LibmemcachedStoreTest < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@store = ActiveSupport::Cache.lookup_store :libmemcached_store
|
16
|
-
@store.clear
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_should_identify_cache_store
|
20
|
-
assert_kind_of ActiveSupport::Cache::LibmemcachedStore, @store
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_should_set_server_addresses_to_localhost_if_none_are_given
|
24
|
-
assert_equal %w(localhost), @store.addresses
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_set_custom_server_addresses
|
28
|
-
store = ActiveSupport::Cache.lookup_store :libmemcached_store, 'localhost', '192.168.1.1'
|
29
|
-
assert_equal %w(localhost 192.168.1.1), store.addresses
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_should_enable_consistent_hashing_by_default
|
33
|
-
assert_equal :consistent, @store.options[:distribution]
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_enable_non_blocking_io_by_default
|
37
|
-
assert_equal true, @store.options[:no_block]
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_enable_server_failover_by_default
|
41
|
-
assert_equal true, @store.options[:auto_eject_hosts]
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_allow_configuration_of_custom_options
|
45
|
-
options = {
|
46
|
-
:prefix_key => 'test',
|
47
|
-
:distribution => :modula,
|
48
|
-
:no_block => false,
|
49
|
-
:auto_eject_hosts => false
|
50
|
-
}
|
51
|
-
|
52
|
-
store = ActiveSupport::Cache.lookup_store :libmemcached_store, 'localhost', options
|
53
|
-
|
54
|
-
assert_equal 'test', store.instance_variable_get(:@cache).prefix_key
|
55
|
-
assert_equal :modula, store.options[:distribution]
|
56
|
-
assert_equal false, store.options[:no_block]
|
57
|
-
assert_equal false, store.options[:auto_eject_hosts]
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_use_local_cache
|
61
|
-
@store.with_local_cache do
|
62
|
-
@store.write('key', 'value')
|
63
|
-
assert_equal 'value', @store.send(:local_cache).read('key')
|
64
|
-
end
|
65
|
-
|
66
|
-
assert_equal 'value', @store.read('key')
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_should_read_multiple_keys
|
70
|
-
@store.write('a', 1)
|
71
|
-
@store.write('b', 2)
|
72
|
-
|
73
|
-
assert_equal({ 'a' => 1, 'b' => 2 }, @store.read_multi('a', 'b', 'c'))
|
74
|
-
assert_equal({}, @store.read_multi())
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_should_fix_long_keys
|
78
|
-
key = ("0123456789" * 100).freeze
|
79
|
-
assert key.size > 250
|
80
|
-
@store.write(key, 1)
|
81
|
-
assert_equal 1, @store.read(key)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|