cache 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/BENCHMARKS +98 -0
- data/README.rdoc +11 -3
- data/cache.gemspec +2 -2
- data/lib/cache/config.rb +7 -1
- data/lib/cache/storage.rb +9 -0
- data/lib/cache/version.rb +1 -1
- data/test/helper.rb +2 -0
- data/test/profile/benchmark.rb +4 -2
- data/test/test_default_storage.rb +16 -0
- metadata +21 -19
data/BENCHMARKS
CHANGED
@@ -1,3 +1,101 @@
|
|
1
|
+
# sabshere 2/22/11 v0.0.3
|
2
|
+
|
3
|
+
vidalia:~/github/cache (master) $ ruby test/profile/benchmark.rb
|
4
|
+
Darwin vidalia 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386
|
5
|
+
ruby 1.8.7 (2010-05-25 patchlevel 266) [i686-darwin9.8.0]
|
6
|
+
RUBY_VERSION=ruby-1.8.7-head
|
7
|
+
Ruby 1.8.7p266
|
8
|
+
Loaded memcached 1.0.6
|
9
|
+
Loaded remix-stash 1.1.3
|
10
|
+
Loaded memcache-client 1.8.5
|
11
|
+
Loaded cache 0.0.3
|
12
|
+
Loaded kgio 2.3.2
|
13
|
+
Loaded dalli 1.0.2
|
14
|
+
Loops is 20000
|
15
|
+
Stack depth is 0
|
16
|
+
Small value size is: 13 bytes
|
17
|
+
Large value size is: 4158 bytes
|
18
|
+
No matching processes belonging to you were found
|
19
|
+
user system total real
|
20
|
+
set: cache:dalli:bin 6.020000 1.890000 7.910000 ( 10.568499)
|
21
|
+
set: cache:libm:bin 1.460000 1.280000 2.740000 ( 6.112829)
|
22
|
+
set: dalli:bin 5.640000 1.870000 7.510000 ( 10.215219)
|
23
|
+
set: libm:ascii 0.820000 1.320000 2.140000 ( 5.446435)
|
24
|
+
set: libm:ascii:pipeline 0.360000 0.010000 0.370000 ( 0.378485)
|
25
|
+
set: libm:ascii:udp 0.700000 0.720000 1.420000 ( 3.659001)
|
26
|
+
set: libm:bin 0.720000 1.340000 2.060000 ( 5.364179)
|
27
|
+
set: libm:bin:buffer 0.300000 0.120000 0.420000 ( 1.105467)
|
28
|
+
set: mclient:ascii 10.860000 3.820000 14.680000 ( 15.175516)
|
29
|
+
set: stash:bin 3.700000 1.350000 5.050000 ( 8.229477)
|
30
|
+
|
31
|
+
get: cache:dalli:bin 6.130000 2.070000 8.200000 ( 10.683650)
|
32
|
+
get: cache:libm:bin 1.440000 1.230000 2.670000 ( 5.908044)
|
33
|
+
get: dalli:bin 5.800000 2.080000 7.880000 ( 10.324650)
|
34
|
+
get: libm:ascii 0.970000 1.320000 2.290000 ( 5.582769)
|
35
|
+
get: libm:ascii:pipeline 1.050000 1.580000 2.630000 ( 5.956804)
|
36
|
+
get: libm:ascii:udp 0.820000 0.720000 1.540000 ( 3.605324)
|
37
|
+
get: libm:bin 0.820000 1.340000 2.160000 ( 5.329828)
|
38
|
+
get: libm:bin:buffer 0.940000 1.630000 2.570000 ( 5.748327)
|
39
|
+
get: mclient:ascii 12.900000 3.860000 16.760000 ( 17.249089)
|
40
|
+
get: stash:bin 3.360000 1.320000 4.680000 ( 7.949412)
|
41
|
+
|
42
|
+
delete: cache:dalli:bin 5.610000 2.100000 7.710000 ( 10.029324)
|
43
|
+
delete: cache:libm:bin 2.030000 1.370000 3.400000 ( 6.651471)
|
44
|
+
delete: dalli:bin 5.230000 2.110000 7.340000 ( 9.676535)
|
45
|
+
delete: libm:ascii 1.790000 1.380000 3.170000 ( 6.550488)
|
46
|
+
delete: libm:ascii:pipeline 0.570000 0.650000 1.220000 ( 1.346079)
|
47
|
+
delete: libm:ascii:udp 1.650000 0.870000 2.520000 ( 4.527372)
|
48
|
+
delete: libm:bin 1.730000 1.390000 3.120000 ( 6.469119)
|
49
|
+
delete: libm:bin:buffer 0.480000 0.550000 1.030000 ( 1.773955)
|
50
|
+
delete: mclient:ascii 10.890000 3.930000 14.820000 ( 15.286474)
|
51
|
+
delete:stash:bin => #<NoMethodError: undefined method `delete' for #<Remix::Stash:0x11cc360>>
|
52
|
+
|
53
|
+
get-missing: cache:dalli:bin 5.970000 2.260000 8.230000 ( 10.874274)
|
54
|
+
get-missing: cache:libm:bin 2.470000 1.580000 4.050000 ( 7.471236)
|
55
|
+
get-missing: dalli:bin 5.550000 2.230000 7.780000 ( 10.420783)
|
56
|
+
get-missing: libm:ascii 2.080000 1.560000 3.640000 ( 7.186221)
|
57
|
+
get-missing: libm:ascii:pipeline 2.160000 1.890000 4.050000 ( 7.482394)
|
58
|
+
get-missing: libm:ascii:udp 1.850000 0.930000 2.780000 ( 4.956340)
|
59
|
+
get-missing: libm:bin 2.030000 1.470000 3.500000 ( 7.022853)
|
60
|
+
get-missing: libm:bin:buffer 2.090000 1.890000 3.980000 ( 7.314636)
|
61
|
+
get-missing: mclient:ascii 11.500000 4.010000 15.510000 ( 16.029498)
|
62
|
+
get-missing: stash:bin 3.280000 1.390000 4.670000 ( 7.834190)
|
63
|
+
|
64
|
+
set-large: cache:dalli:bin 8.070000 2.080000 10.150000 ( 13.126027)
|
65
|
+
set-large: cache:libm:bin 2.530000 1.410000 3.940000 ( 7.636479)
|
66
|
+
set-large: dalli:bin 7.650000 2.070000 9.720000 ( 12.691443)
|
67
|
+
set-large: libm:ascii 0.930000 1.420000 2.350000 ( 6.066637)
|
68
|
+
set-large: libm:ascii:pipeline 0.640000 0.450000 1.090000 ( 1.279625)
|
69
|
+
set-large: libm:ascii:udp 0.820000 0.860000 1.680000 ( 4.318411)
|
70
|
+
set-large: libm:bin 0.810000 1.450000 2.260000 ( 5.870205)
|
71
|
+
set-large: libm:bin:buffer 0.590000 0.660000 1.250000 ( 2.492524)
|
72
|
+
set-large: mclient:ascii 12.290000 4.120000 16.410000 ( 17.042205)
|
73
|
+
set-large: stash:bin 5.810000 1.430000 7.240000 ( 10.615813)
|
74
|
+
|
75
|
+
get-large: cache:dalli:bin 7.680000 2.460000 10.140000 ( 13.286558)
|
76
|
+
get-large: cache:libm:bin 6.530000 1.500000 8.030000 ( 11.980532)
|
77
|
+
get-large: dalli:bin 7.240000 2.460000 9.700000 ( 12.743058)
|
78
|
+
get-large: libm:ascii 1.610000 1.540000 3.150000 ( 7.086940)
|
79
|
+
get-large: libm:ascii:pipeline 1.720000 1.890000 3.610000 ( 7.410838)
|
80
|
+
get-large: libm:ascii:udp 1.420000 0.960000 2.380000 ( 4.688834)
|
81
|
+
get-large: libm:bin 1.440000 1.590000 3.030000 ( 6.935013)
|
82
|
+
get-large: libm:bin:buffer 1.600000 1.920000 3.520000 ( 7.278831)
|
83
|
+
get-large: mclient:ascii 15.700000 4.800000 20.500000 ( 21.276235)
|
84
|
+
get-large: stash:bin 3.580000 1.420000 5.000000 ( 8.259296)
|
85
|
+
|
86
|
+
hash:hsieh 0.310000 0.000000 0.310000 ( 0.314801)
|
87
|
+
hash:none 0.320000 0.000000 0.320000 ( 0.317238)
|
88
|
+
hash:default 0.610000 0.000000 0.610000 ( 0.627191)
|
89
|
+
hash:fnv1_64 1.270000 0.010000 1.280000 ( 1.274384)
|
90
|
+
hash:md5 1.070000 0.000000 1.070000 ( 1.080698)
|
91
|
+
hash:murmur 0.560000 0.000000 0.560000 ( 0.570058)
|
92
|
+
hash:fnv1a_64 0.690000 0.000000 0.690000 ( 0.701543)
|
93
|
+
hash:fnv1a_32 0.680000 0.010000 0.690000 ( 0.684682)
|
94
|
+
hash:jenkins 0.660000 0.000000 0.660000 ( 0.668542)
|
95
|
+
hash:crc 0.660000 0.000000 0.660000 ( 0.665331)
|
96
|
+
hash:fnv1_32 0.630000 0.000000 0.630000 ( 0.636520)
|
97
|
+
vidalia:~/github/cache (master) $
|
98
|
+
|
1
99
|
# sabshere 2/22/11 v0.0.2
|
2
100
|
|
3
101
|
Darwin vidalia 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386
|
data/README.rdoc
CHANGED
@@ -6,22 +6,30 @@ Takes care of exceptions like Memcached::NotFound and also forking/threading.
|
|
6
6
|
|
7
7
|
== Example
|
8
8
|
|
9
|
+
It uses a (useless?) memory store by default:
|
10
|
+
|
11
|
+
cache = Cache.new
|
12
|
+
cache.set 'hello'
|
13
|
+
cache.get 'hello', 'world'
|
14
|
+
|
15
|
+
You can specify a more useful cache client:
|
16
|
+
|
9
17
|
require 'memcached' # a really fast memcached client gem
|
10
|
-
require '
|
18
|
+
require 'cache' # this gem, which provides a standard interface
|
11
19
|
raw_client = Memcached.new '127.0.0.1:11211'
|
12
20
|
cache = Cache.new raw_client
|
13
21
|
|
14
22
|
or
|
15
23
|
|
16
24
|
require 'redis' # the redis key-value store
|
17
|
-
require '
|
25
|
+
require 'cache' # this gem, which provides a standard interface
|
18
26
|
raw_client = Redis.new
|
19
27
|
cache = Cache.new raw_client
|
20
28
|
|
21
29
|
or
|
22
30
|
|
23
31
|
require 'dalli' # the dalli memcached client used by heroku
|
24
|
-
require '
|
32
|
+
require 'cache' # this gem, which provides a standard interface
|
25
33
|
raw_client = Dalli::Client.new
|
26
34
|
cache = Cache.new raw_client
|
27
35
|
|
data/cache.gemspec
CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
+
s.add_dependency 'activesupport', '>=2.3.11' # for default memory store
|
23
|
+
s.add_dependency 'i18n' # activesupport
|
22
24
|
s.add_development_dependency 'test-unit'
|
23
25
|
s.add_development_dependency 'redis'
|
24
26
|
s.add_development_dependency 'dalli'
|
25
|
-
s.add_development_dependency 'activesupport', '>=2.3.4' # for DalliStore
|
26
|
-
s.add_development_dependency 'i18n' # activesupport
|
27
27
|
s.add_development_dependency 'memcached'
|
28
28
|
s.add_development_dependency 'memcache-client'
|
29
29
|
end
|
data/lib/cache/config.rb
CHANGED
@@ -22,7 +22,13 @@ class Cache
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def client #:nodoc:
|
25
|
-
@client
|
25
|
+
if @client.nil?
|
26
|
+
require 'active_support/cache'
|
27
|
+
require 'active_support/cache/memory_store'
|
28
|
+
@client = ::ActiveSupport::Cache::MemoryStore.new
|
29
|
+
else
|
30
|
+
@client
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
# TTL for method caches. Defaults to 60 seconds.
|
data/lib/cache/storage.rb
CHANGED
@@ -74,6 +74,7 @@ class Cache
|
|
74
74
|
|
75
75
|
def reset_if_forked_or_threaded
|
76
76
|
if fork_detected?
|
77
|
+
$stderr.puts "fork detected" if ENV['CACHE_DEBUG'] == 'true'
|
77
78
|
if dalli?
|
78
79
|
parent.config.client.close
|
79
80
|
elsif dalli_store?
|
@@ -88,6 +89,7 @@ class Cache
|
|
88
89
|
parent.config.client.reset
|
89
90
|
end
|
90
91
|
elsif new_thread_detected?
|
92
|
+
$stderr.puts "new thread detected" if ENV['CACHE_DEBUG'] == 'true'
|
91
93
|
if memcached? or memcached_rails?
|
92
94
|
cloned_client = parent.config.client.clone
|
93
95
|
parent.config.client = cloned_client
|
@@ -129,6 +131,13 @@ class Cache
|
|
129
131
|
answer
|
130
132
|
end
|
131
133
|
|
134
|
+
def memory_store?
|
135
|
+
return @memory_store_query[0] if @memory_store_query.is_a?(::Array)
|
136
|
+
answer = (defined?(::ActiveSupport::Cache::MemoryStore) and bare_client.is_a?(::ActiveSupport::Cache::MemoryStore))
|
137
|
+
@memory_store_query = [answer]
|
138
|
+
answer
|
139
|
+
end
|
140
|
+
|
132
141
|
def mem_cache?
|
133
142
|
return @mem_cache_query[0] if @mem_cache_query.is_a?(::Array)
|
134
143
|
answer = (defined?(::MemCache) and bare_client.is_a?(::MemCache))
|
data/lib/cache/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/profile/benchmark.rb
CHANGED
@@ -3,7 +3,7 @@ HERE = File.dirname(__FILE__)
|
|
3
3
|
$LOAD_PATH << "#{HERE}/../../lib/"
|
4
4
|
UNIX_SOCKET_NAME = File.join(ENV['TMPDIR']||'/tmp','memcached')
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'cache'
|
7
7
|
require 'benchmark'
|
8
8
|
require 'rubygems'
|
9
9
|
require 'ruby-debug' if ENV['DEBUG']
|
@@ -26,6 +26,8 @@ puts "Ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
|
|
26
26
|
puts "Loaded #{gem_name} #{Gem.loaded_specs[gem_name].version.to_s rescue nil}"
|
27
27
|
end
|
28
28
|
|
29
|
+
MEMCACHED_HERE = File.expand_path(File.join(File.dirname(Gem.required_location('memcached', 'memcached.rb')), '..', 'test', 'profile'))
|
30
|
+
|
29
31
|
class Remix::Stash
|
30
32
|
# Remix::Stash API doesn't let you set servers
|
31
33
|
@@clusters = {:default => Remix::Stash::Cluster.new(['127.0.0.1:43042', '127.0.0.1:43043'])}
|
@@ -100,7 +102,7 @@ class Bench
|
|
100
102
|
private
|
101
103
|
|
102
104
|
def reset_servers
|
103
|
-
system("ruby #{
|
105
|
+
system("ruby #{MEMCACHED_HERE}/../setup.rb")
|
104
106
|
sleep(1)
|
105
107
|
end
|
106
108
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
require 'active_support/cache'
|
4
|
+
require 'active_support/cache/memory_store'
|
5
|
+
|
6
|
+
class TestDefaultStorage < Test::Unit::TestCase
|
7
|
+
def raw_client
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_query
|
12
|
+
assert @cache.storage.send(:memory_store?)
|
13
|
+
end
|
14
|
+
|
15
|
+
include SharedTests
|
16
|
+
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Seamus Abshere
|
@@ -15,25 +15,27 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-24 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: activesupport
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 21
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
|
33
|
-
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 11
|
34
|
+
version: 2.3.11
|
35
|
+
type: :runtime
|
34
36
|
version_requirements: *id001
|
35
37
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
38
|
+
name: i18n
|
37
39
|
prerelease: false
|
38
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
@@ -44,10 +46,10 @@ dependencies:
|
|
44
46
|
segments:
|
45
47
|
- 0
|
46
48
|
version: "0"
|
47
|
-
type: :
|
49
|
+
type: :runtime
|
48
50
|
version_requirements: *id002
|
49
51
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
52
|
+
name: test-unit
|
51
53
|
prerelease: false
|
52
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
55
|
none: false
|
@@ -61,23 +63,21 @@ dependencies:
|
|
61
63
|
type: :development
|
62
64
|
version_requirements: *id003
|
63
65
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
66
|
+
name: redis
|
65
67
|
prerelease: false
|
66
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
69
|
none: false
|
68
70
|
requirements:
|
69
71
|
- - ">="
|
70
72
|
- !ruby/object:Gem::Version
|
71
|
-
hash:
|
73
|
+
hash: 3
|
72
74
|
segments:
|
73
|
-
-
|
74
|
-
|
75
|
-
- 4
|
76
|
-
version: 2.3.4
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
77
|
type: :development
|
78
78
|
version_requirements: *id004
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
-
name:
|
80
|
+
name: dalli
|
81
81
|
prerelease: false
|
82
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- test/shared_tests.rb
|
144
144
|
- test/test_dalli_storage.rb
|
145
145
|
- test/test_dalli_store_storage.rb
|
146
|
+
- test/test_default_storage.rb
|
146
147
|
- test/test_memcache_storage.rb
|
147
148
|
- test/test_memcached_rails_storage.rb
|
148
149
|
- test/test_memcached_storage.rb
|
@@ -187,6 +188,7 @@ test_files:
|
|
187
188
|
- test/shared_tests.rb
|
188
189
|
- test/test_dalli_storage.rb
|
189
190
|
- test/test_dalli_store_storage.rb
|
191
|
+
- test/test_default_storage.rb
|
190
192
|
- test/test_memcache_storage.rb
|
191
193
|
- test/test_memcached_rails_storage.rb
|
192
194
|
- test/test_memcached_storage.rb
|