libmemcached_store 0.2.2 → 0.2.3

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.
@@ -1,4 +1,5 @@
1
1
  require 'memcached'
2
+ require 'digest/sha1'
2
3
 
3
4
  class Memcached
4
5
  # The latest version of memcached (0.11) doesn't support hostnames with dashes
@@ -32,9 +33,21 @@ module ActiveSupport
32
33
  extend ActiveSupport::Cache::Strategy::LocalCache
33
34
  end
34
35
 
36
+ def valid_key(key)
37
+ if key.is_a?(Array)
38
+ key.map {|k| valid_key(k) }
39
+ else
40
+ if key && key.size > 250
41
+ "#{Digest::SHA1.hexdigest(key)}-autofixed"
42
+ else
43
+ key
44
+ end
45
+ end
46
+ end
47
+
35
48
  def read(key, options = nil)
36
49
  super
37
- @cache.get(key, marshal?(options))
50
+ @cache.get(valid_key(key), marshal?(options))
38
51
  rescue Memcached::NotFound
39
52
  nil
40
53
  rescue Memcached::Error => e
@@ -51,7 +64,7 @@ module ActiveSupport
51
64
  def write(key, value, options = nil)
52
65
  super
53
66
  method = (options && options[:unless_exist]) ? :add : :set
54
- @cache.send(method, key, value, expires_in(options), marshal?(options))
67
+ @cache.send(method, valid_key(key), value, expires_in(options), marshal?(options))
55
68
  true
56
69
  rescue Memcached::Error => e
57
70
  log_error(e)
@@ -60,10 +73,10 @@ module ActiveSupport
60
73
 
61
74
  def delete(key, options = nil)
62
75
  super
63
- @cache.delete(key)
76
+ @cache.delete(valid_key(key))
64
77
  true
65
78
  rescue Memcached::NotFound
66
- nil
79
+ nil
67
80
  rescue Memcached::Error => e
68
81
  log_error(e)
69
82
  false
@@ -75,14 +88,14 @@ module ActiveSupport
75
88
 
76
89
  def increment(key, amount=1)
77
90
  log 'incrementing', key, amount
78
- @cache.incr(key, amount)
91
+ @cache.incr(valid_key(key), amount)
79
92
  rescue Memcached::Error
80
93
  nil
81
94
  end
82
95
 
83
96
  def decrement(key, amount=1)
84
97
  log 'decrementing', key, amount
85
- @cache.decr(key, amount)
98
+ @cache.decr(valid_key(key), amount)
86
99
  rescue Memcached::Error
87
100
  nil
88
101
  end
@@ -13,6 +13,7 @@ end
13
13
  class LibmemcachedStoreTest < Test::Unit::TestCase
14
14
  def setup
15
15
  @store = ActiveSupport::Cache.lookup_store :libmemcached_store
16
+ @store.clear
16
17
  end
17
18
 
18
19
  def test_should_identify_cache_store
@@ -55,22 +56,29 @@ class LibmemcachedStoreTest < Test::Unit::TestCase
55
56
  assert_equal false, store.options[:no_block]
56
57
  assert_equal false, store.options[:auto_eject_hosts]
57
58
  end
58
-
59
+
59
60
  def test_should_use_local_cache
60
61
  @store.with_local_cache do
61
62
  @store.write('key', 'value')
62
- assert_equal 'value', @store.send(:local_cache).read('key')
63
+ assert_equal 'value', @store.send(:local_cache).read('key')
63
64
  end
64
-
65
+
65
66
  assert_equal 'value', @store.read('key')
66
67
  end
67
-
68
- def test_should_read_multiple_keys
68
+
69
+ def test_should_read_multiple_keys
69
70
  @store.write('a', 1)
70
71
  @store.write('b', 2)
71
-
72
+
72
73
  assert_equal({ 'a' => 1, 'b' => 2 }, @store.read_multi('a', 'b', 'c'))
73
74
  assert_equal({}, @store.read_multi())
74
75
  end
75
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
+
76
84
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libmemcached_store
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeffrey Hardy
@@ -15,11 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-24 00:00:00 -07:00
19
- default_executable:
18
+ date: 2012-04-16 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: memcached
21
+ name: rake
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
@@ -30,36 +29,60 @@ dependencies:
30
29
  segments:
31
30
  - 0
32
31
  version: "0"
33
- type: :runtime
32
+ type: :development
34
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: memcached
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: activesupport
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - <
55
+ - !ruby/object:Gem::Version
56
+ hash: 5
57
+ segments:
58
+ - 3
59
+ version: "3"
60
+ type: :runtime
61
+ version_requirements: *id003
35
62
  description: |-
36
63
  An ActiveSupport cache store that uses the C-based libmemcached client through
37
64
  Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast, lightweight,
38
65
  and supports consistent hashing, non-blocking IO, and graceful server failover.
39
- email: packagethief@gmail.com
66
+ email:
67
+ - packagethief@gmail.com
40
68
  executables: []
41
69
 
42
70
  extensions: []
43
71
 
44
- extra_rdoc_files:
45
- - README
72
+ extra_rdoc_files: []
73
+
46
74
  files:
47
- - .gitignore
48
- - MIT-LICENSE
49
- - README
50
- - Rakefile
51
75
  - lib/active_support/cache/compressed_libmemcached_store.rb
52
76
  - lib/active_support/cache/libmemcached_store.rb
53
77
  - lib/libmemcached_store.rb
54
- - libmemcached_store.gemspec
78
+ - README
55
79
  - test/libmemcached_store_test.rb
56
- has_rdoc: true
57
80
  homepage: http://github.com/37signals/libmemcached_store
58
81
  licenses: []
59
82
 
60
83
  post_install_message:
61
- rdoc_options:
62
- - --charset=UTF-8
84
+ rdoc_options: []
85
+
63
86
  require_paths:
64
87
  - lib
65
88
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -83,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
106
  requirements: []
84
107
 
85
108
  rubyforge_project:
86
- rubygems_version: 1.3.7
109
+ rubygems_version: 1.8.21
87
110
  signing_key:
88
111
  specification_version: 3
89
112
  summary: ActiveSupport::Cache wrapper for libmemcached
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- .DS_Store
2
- pkg/
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2008 37signals
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,40 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gemspec|
8
- gemspec.name = "libmemcached_store"
9
- gemspec.version = '0.2.2'
10
- gemspec.summary = "ActiveSupport::Cache wrapper for libmemcached "
11
- gemspec.description = "An ActiveSupport cache store that uses the C-based libmemcached client through
12
- Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast, lightweight,
13
- and supports consistent hashing, non-blocking IO, and graceful server failover."
14
- gemspec.email = "packagethief@gmail.com"
15
- gemspec.homepage = "http://github.com/37signals/libmemcached_store"
16
- gemspec.authors = ["Jeffrey Hardy"]
17
- gemspec.add_runtime_dependency 'memcached'
18
- end
19
- rescue LoadError
20
- puts "Jeweler not available. Install it with: gem install jeweler"
21
- end
22
-
23
- desc 'Default: run unit tests.'
24
- task :default => :test
25
-
26
- desc 'Test the libmemcached_store plugin.'
27
- Rake::TestTask.new(:test) do |t|
28
- t.libs << 'lib'
29
- t.pattern = 'test/**/*_test.rb'
30
- t.verbose = true
31
- end
32
-
33
- desc 'Generate documentation for the libmemcached_store plugin.'
34
- Rake::RDocTask.new(:rdoc) do |rdoc|
35
- rdoc.rdoc_dir = 'rdoc'
36
- rdoc.title = 'LibmemcachedStore'
37
- rdoc.options << '--line-numbers' << '--inline-source'
38
- rdoc.rdoc_files.include('README')
39
- rdoc.rdoc_files.include('lib/**/*.rb')
40
- end
@@ -1,53 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{libmemcached_store}
8
- s.version = "0.2.2"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Jeffrey Hardy"]
12
- s.date = %q{2010-08-24}
13
- s.description = %q{An ActiveSupport cache store that uses the C-based libmemcached client through
14
- Evan Weaver's Ruby/SWIG wrapper, memcached. libmemcached is fast, lightweight,
15
- and supports consistent hashing, non-blocking IO, and graceful server failover.}
16
- s.email = %q{packagethief@gmail.com}
17
- s.extra_rdoc_files = [
18
- "README"
19
- ]
20
- s.files = [
21
- ".gitignore",
22
- "MIT-LICENSE",
23
- "README",
24
- "Rakefile",
25
- "lib/active_support/cache/compressed_libmemcached_store.rb",
26
- "lib/active_support/cache/libmemcached_store.rb",
27
- "lib/libmemcached_store.rb",
28
- "libmemcached_store.gemspec",
29
- "test/libmemcached_store_test.rb"
30
- ]
31
- s.homepage = %q{http://github.com/37signals/libmemcached_store}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
35
- s.summary = %q{ActiveSupport::Cache wrapper for libmemcached}
36
- s.test_files = [
37
- "test/libmemcached_store_test.rb"
38
- ]
39
-
40
- if s.respond_to? :specification_version then
41
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
- s.specification_version = 3
43
-
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_runtime_dependency(%q<memcached>, [">= 0"])
46
- else
47
- s.add_dependency(%q<memcached>, [">= 0"])
48
- end
49
- else
50
- s.add_dependency(%q<memcached>, [">= 0"])
51
- end
52
- end
53
-