method_cache 0.6.4 → 1.0.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/.gitignore +4 -0
- data/.rbenv-gemsets +1 -0
- data/.rbenv-version +1 -0
- data/Gemfile +3 -0
- data/Rakefile +2 -37
- data/VERSION +1 -0
- data/lib/method_cache/local_cache.rb +67 -0
- data/lib/method_cache/proxy.rb +69 -15
- data/lib/method_cache.rb +14 -7
- data/method_cache.gemspec +21 -42
- data/test/method_cache_remote_test.rb +25 -0
- data/test/method_cache_test.rb +82 -6
- data/test/test_helper.rb +6 -1
- metadata +95 -15
- data/VERSION.yml +0 -5
data/.gitignore
ADDED
data/.rbenv-gemsets
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
method_cache
|
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ree-1.8.7-2012.02
|
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,45 +1,10 @@
|
|
1
|
-
require 'rake'
|
2
1
|
require 'rake/testtask'
|
3
|
-
require '
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'jeweler'
|
7
|
-
Jeweler::Tasks.new do |s|
|
8
|
-
s.name = "method_cache"
|
9
|
-
s.summary = %Q{Simple memcache-based memoization library for Ruby}
|
10
|
-
s.email = "code@justinbalthrop.com"
|
11
|
-
s.homepage = "http://github.com/ninjudd/method_cache"
|
12
|
-
s.description = "Simple memcache-based memoization library for Ruby"
|
13
|
-
s.authors = ["Justin Balthrop"]
|
14
|
-
s.add_dependency('memcache', '>= 1.0.0')
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
19
|
-
end
|
2
|
+
require 'bundler/gem_tasks'
|
20
3
|
|
21
4
|
Rake::TestTask.new do |t|
|
22
|
-
t.libs
|
5
|
+
t.libs = ['lib', 'test']
|
23
6
|
t.pattern = 'test/**/*_test.rb'
|
24
7
|
t.verbose = false
|
25
8
|
end
|
26
9
|
|
27
|
-
Rake::RDocTask.new do |rdoc|
|
28
|
-
rdoc.rdoc_dir = 'rdoc'
|
29
|
-
rdoc.title = 'method_cache'
|
30
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
31
|
-
rdoc.rdoc_files.include('README*')
|
32
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
33
|
-
end
|
34
|
-
|
35
|
-
begin
|
36
|
-
require 'rcov/rcovtask'
|
37
|
-
Rcov::RcovTask.new do |t|
|
38
|
-
t.libs << 'test'
|
39
|
-
t.test_files = FileList['test/**/*_test.rb']
|
40
|
-
t.verbose = true
|
41
|
-
end
|
42
|
-
rescue LoadError
|
43
|
-
end
|
44
|
-
|
45
10
|
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module MethodCache
|
2
|
+
class LocalCache
|
3
|
+
def initialize
|
4
|
+
clear
|
5
|
+
end
|
6
|
+
|
7
|
+
def clear
|
8
|
+
@data = {}
|
9
|
+
@cached_at = {}
|
10
|
+
@expires_at = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(key)
|
14
|
+
if expires = expires_at(key)
|
15
|
+
delete(key) if expires <= Time.now
|
16
|
+
end
|
17
|
+
@data[key]
|
18
|
+
end
|
19
|
+
alias [] get
|
20
|
+
|
21
|
+
def count(key)
|
22
|
+
get(key).to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def set(key, value, expiry)
|
26
|
+
@cached_at[key] = Time.now
|
27
|
+
@expires_at[key] = expiry_to_time(expiry)
|
28
|
+
@data[key] = value
|
29
|
+
end
|
30
|
+
alias []= set
|
31
|
+
alias write set
|
32
|
+
|
33
|
+
def delete(key)
|
34
|
+
@cached_at.delete(key)
|
35
|
+
@expires_at.delete(key)
|
36
|
+
@data.delete(key)
|
37
|
+
end
|
38
|
+
|
39
|
+
def incr(key, amount)
|
40
|
+
@data[key] = count(key) + amount
|
41
|
+
end
|
42
|
+
|
43
|
+
def decr(key, amount)
|
44
|
+
incr(key, -amount)
|
45
|
+
end
|
46
|
+
|
47
|
+
def expires_at(key)
|
48
|
+
@expires_at[key]
|
49
|
+
end
|
50
|
+
|
51
|
+
def cached_at(key)
|
52
|
+
@cached_at[key]
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def expiry_to_time(expiry)
|
58
|
+
expiry = Time.at(expiry) if expiry > 60*60*24*30
|
59
|
+
if expiry.kind_of?(Time)
|
60
|
+
expiry
|
61
|
+
else
|
62
|
+
expiry = expiry.to_i
|
63
|
+
expiry == 0 ? nil : Time.now + expiry
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/method_cache/proxy.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'digest/sha1'
|
2
2
|
|
3
|
+
class Object
|
4
|
+
def metaclass; class << self; self; end; end
|
5
|
+
end
|
6
|
+
|
3
7
|
module MethodCache
|
4
8
|
class Proxy
|
5
9
|
attr_reader :method_name, :opts, :args, :target
|
@@ -44,13 +48,22 @@ module MethodCache
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def update
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
if block_given?
|
52
|
+
old_value = read_from_cache(key)
|
53
|
+
return if old_value.nil?
|
54
|
+
|
55
|
+
old_value = nil if old_value == NULL
|
56
|
+
new_value = yield(old_value)
|
57
|
+
return if old_value == new_value
|
58
|
+
else
|
59
|
+
new_value = target.send(method_name_without_caching, *args)
|
60
|
+
end
|
61
|
+
write_to_cache(key, new_value)
|
62
|
+
new_value
|
50
63
|
end
|
51
64
|
|
52
65
|
def value
|
53
|
-
value =
|
66
|
+
value = read_from_cache(key)
|
54
67
|
value = nil unless valid?(:load, value)
|
55
68
|
|
56
69
|
if value.nil?
|
@@ -59,6 +72,11 @@ module MethodCache
|
|
59
72
|
write_to_cache(key, value) if valid?(:save, value)
|
60
73
|
end
|
61
74
|
|
75
|
+
if opts[:counter]
|
76
|
+
value = [value, opts[:max]].min if opts[:max]
|
77
|
+
value = [value, opts[:min]].max if opts[:min]
|
78
|
+
end
|
79
|
+
|
62
80
|
value = nil if value == NULL
|
63
81
|
if clone? and value
|
64
82
|
value.clone
|
@@ -98,12 +116,19 @@ module MethodCache
|
|
98
116
|
if @cache.nil?
|
99
117
|
@cache = opts[:cache] || MethodCache.default_cache
|
100
118
|
@cache = Memcache.pool[@cache] if @cache.kind_of?(Symbol)
|
119
|
+
if not @cache.respond_to?(:[]) and @cache.respond_to?(:get)
|
120
|
+
@cache.metaclass.module_eval do
|
121
|
+
define_method :[] do |key|
|
122
|
+
get(key)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
101
126
|
end
|
102
127
|
@cache
|
103
128
|
end
|
104
129
|
|
105
130
|
def local?
|
106
|
-
cache.kind_of?(Hash)
|
131
|
+
cache.kind_of?(LocalCache) or cache.kind_of?(Hash)
|
107
132
|
end
|
108
133
|
|
109
134
|
def clone?
|
@@ -121,10 +146,23 @@ module MethodCache
|
|
121
146
|
@key
|
122
147
|
end
|
123
148
|
|
149
|
+
def cached_at
|
150
|
+
cache.cached_at(key) if cache.respond_to?(:cached_at)
|
151
|
+
end
|
152
|
+
|
153
|
+
def expires_at
|
154
|
+
cache.expires_at(key) if cache.respond_to?(:expires_at)
|
155
|
+
end
|
156
|
+
|
124
157
|
private
|
125
158
|
|
126
159
|
def expiry(value)
|
127
|
-
dynamic_opt(:expiry, value).to_i
|
160
|
+
value = dynamic_opt(:expiry, value).to_i
|
161
|
+
if defined?(Memcache) and cache.kind_of?(Memcache)
|
162
|
+
{:expiry => value}
|
163
|
+
else
|
164
|
+
value
|
165
|
+
end
|
128
166
|
end
|
129
167
|
|
130
168
|
def valid?(type, value)
|
@@ -137,12 +175,17 @@ module MethodCache
|
|
137
175
|
|
138
176
|
def dynamic_opt(name, value = nil)
|
139
177
|
if opts[name].kind_of?(Proc)
|
140
|
-
proc = opts[name]
|
178
|
+
proc = opts[name]
|
141
179
|
case proc.arity
|
142
|
-
when 0 then
|
143
|
-
when 1 then
|
180
|
+
when 0 then target.instance_exec(&proc)
|
181
|
+
when 1 then target.instance_exec(value, &proc)
|
144
182
|
else
|
145
|
-
|
183
|
+
meta = {
|
184
|
+
:args => args,
|
185
|
+
:cached_at => cached_at,
|
186
|
+
:expires_at => expires_at,
|
187
|
+
}
|
188
|
+
target.instance_exec(value, meta, &proc)
|
146
189
|
end
|
147
190
|
else
|
148
191
|
opts[name]
|
@@ -150,18 +193,25 @@ module MethodCache
|
|
150
193
|
end
|
151
194
|
|
152
195
|
def write_to_cache(key, value)
|
196
|
+
unless opts[:counter]
|
197
|
+
value = value.nil? ? NULL : value
|
198
|
+
end
|
153
199
|
if cache.kind_of?(Hash)
|
154
200
|
raise 'expiry not permitted when cache is a Hash' if opts[:expiry]
|
155
201
|
raise 'counter cache not permitted when cache is a Hash' if opts[:counter]
|
156
202
|
cache[key] = value
|
157
203
|
elsif opts[:counter]
|
158
|
-
cache.write(key, value.to_s,
|
204
|
+
cache.write(key, value.to_s, expiry(value))
|
159
205
|
else
|
160
|
-
|
161
|
-
cache.set(key, value, :expiry => expiry(value))
|
206
|
+
cache.set(key, value, expiry(value))
|
162
207
|
end
|
163
208
|
end
|
164
209
|
|
210
|
+
def read_from_cache(key)
|
211
|
+
return if MethodCache.disabled?
|
212
|
+
opts[:counter] ? cache.count(key) : cache[key]
|
213
|
+
end
|
214
|
+
|
165
215
|
def increment(amount)
|
166
216
|
raise "cannot increment non-counter method" unless opts[:counter]
|
167
217
|
cache.incr(key, amount)
|
@@ -190,8 +240,12 @@ module MethodCache
|
|
190
240
|
when defined?(ActiveRecord::Base) && ActiveRecord::Base
|
191
241
|
"#{class_key(arg.class)}-#{arg.id}"
|
192
242
|
else
|
193
|
-
|
194
|
-
|
243
|
+
if arg.respond_to?(:method_cache_key)
|
244
|
+
arg.method_cache_key
|
245
|
+
else
|
246
|
+
hash = local? ? arg.hash : Marshal.dump(arg).hash
|
247
|
+
"#{class_key(arg.class)}-#{hash}"
|
248
|
+
end
|
195
249
|
end
|
196
250
|
end
|
197
251
|
|
data/lib/method_cache.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'memcache'
|
2
|
-
|
3
1
|
$:.unshift(File.dirname(__FILE__))
|
2
|
+
require 'method_cache/local_cache'
|
4
3
|
require 'method_cache/proxy'
|
5
4
|
|
6
5
|
module MethodCache
|
@@ -12,7 +11,7 @@ module MethodCache
|
|
12
11
|
return if instance_methods.include?(proxy.method_name_without_caching)
|
13
12
|
|
14
13
|
if cached_instance_methods.empty?
|
15
|
-
include(
|
14
|
+
include(HelperMethods)
|
16
15
|
extend(MethodAdded)
|
17
16
|
end
|
18
17
|
|
@@ -43,7 +42,7 @@ module MethodCache
|
|
43
42
|
return if methods.include?(proxy.method_name_without_caching)
|
44
43
|
|
45
44
|
if cached_class_methods.empty?
|
46
|
-
extend(
|
45
|
+
extend(HelperMethods)
|
47
46
|
extend(SingletonMethodAdded)
|
48
47
|
end
|
49
48
|
|
@@ -72,7 +71,7 @@ module MethodCache
|
|
72
71
|
end
|
73
72
|
|
74
73
|
def self.default_cache
|
75
|
-
@default_cache ||=
|
74
|
+
@default_cache ||= LocalCache.new
|
76
75
|
end
|
77
76
|
|
78
77
|
def cached_instance_methods(method_name = nil)
|
@@ -111,7 +110,7 @@ module MethodCache
|
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
114
|
-
def self.disable(&block)
|
113
|
+
def self.disable(value = true, &block)
|
115
114
|
@disabled, old = true, @disabled
|
116
115
|
yield
|
117
116
|
ensure
|
@@ -122,7 +121,7 @@ module MethodCache
|
|
122
121
|
@disabled
|
123
122
|
end
|
124
123
|
|
125
|
-
module
|
124
|
+
module HelperMethods
|
126
125
|
def invalidate_cached_method(method_name, *args, &block)
|
127
126
|
cached_method(method_name, args).invalidate(&block)
|
128
127
|
end
|
@@ -135,6 +134,14 @@ module MethodCache
|
|
135
134
|
cached_method(method_name, args).update(&block)
|
136
135
|
end
|
137
136
|
|
137
|
+
def method_cached_at(method_name, *args)
|
138
|
+
cached_method(method_name, args).cached_at
|
139
|
+
end
|
140
|
+
|
141
|
+
def method_expires_at(method_name, *args)
|
142
|
+
cached_method(method_name, args).expires_at
|
143
|
+
end
|
144
|
+
|
138
145
|
def without_method_cache(&block)
|
139
146
|
MethodCache.disable(&block)
|
140
147
|
end
|
data/method_cache.gemspec
CHANGED
@@ -1,47 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "method_cache"
|
6
|
+
gem.version = IO.read('VERSION')
|
7
|
+
gem.authors = ["Justin Balthrop"]
|
8
|
+
gem.email = ["git@justinbalthrop.com"]
|
9
|
+
gem.description = %q{Simple memcache-based memoization library for Ruby}
|
10
|
+
gem.summary = gem.description
|
11
|
+
gem.homepage = "https://github.com/ninjudd/method_cache"
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"LICENSE",
|
21
|
-
"README.rdoc",
|
22
|
-
"Rakefile",
|
23
|
-
"VERSION.yml",
|
24
|
-
"lib/method_cache.rb",
|
25
|
-
"lib/method_cache/proxy.rb",
|
26
|
-
"method_cache.gemspec",
|
27
|
-
"test/method_cache_test.rb",
|
28
|
-
"test/test_helper.rb"
|
29
|
-
]
|
30
|
-
s.homepage = %q{http://github.com/ninjudd/method_cache}
|
31
|
-
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version = %q{1.5.2}
|
33
|
-
s.summary = %q{Simple memcache-based memoization library for Ruby}
|
13
|
+
gem.add_development_dependency 'shoulda'
|
14
|
+
gem.add_development_dependency 'mocha'
|
15
|
+
gem.add_development_dependency 'rake'
|
16
|
+
gem.add_development_dependency 'dalli'
|
17
|
+
gem.add_development_dependency 'activesupport', '~> 2.3.9'
|
34
18
|
|
35
|
-
if s.respond_to? :specification_version then
|
36
|
-
s.specification_version = 3
|
37
19
|
|
38
|
-
|
39
|
-
s.add_runtime_dependency(%q<memcache>, [">= 1.0.0"])
|
40
|
-
else
|
41
|
-
s.add_dependency(%q<memcache>, [">= 1.0.0"])
|
42
|
-
end
|
43
|
-
else
|
44
|
-
s.add_dependency(%q<memcache>, [">= 1.0.0"])
|
45
|
-
end
|
46
|
-
end
|
20
|
+
gem.add_dependency 'memcache', '>= 1.0.0'
|
47
21
|
|
22
|
+
gem.files = `git ls-files`.split($/)
|
23
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
24
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
25
|
+
gem.require_paths = ["lib"]
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'dalli'
|
3
|
+
|
4
|
+
PORT = 19112
|
5
|
+
$client = Dalli::Client.new("localhost:#{PORT}")
|
6
|
+
|
7
|
+
class FooBar
|
8
|
+
extend MethodCache
|
9
|
+
|
10
|
+
cache_method :foo, :cache => $client
|
11
|
+
def foo
|
12
|
+
'bar'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MethodCacheRemoteTest < Test::Unit::TestCase
|
17
|
+
|
18
|
+
should 'work with dalli client' do
|
19
|
+
start_memcache(PORT)
|
20
|
+
$client.flush
|
21
|
+
|
22
|
+
f = FooBar.new
|
23
|
+
assert_equal 'bar', f.foo
|
24
|
+
end
|
25
|
+
end
|
data/test/method_cache_test.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'memcache'
|
3
|
+
|
4
|
+
TEST_EXPIRY = 1
|
2
5
|
|
3
6
|
class Foo
|
4
7
|
extend MethodCache
|
@@ -26,11 +29,39 @@ class Foo
|
|
26
29
|
@i ||= 0
|
27
30
|
@i += i
|
28
31
|
end
|
29
|
-
|
32
|
+
|
30
33
|
cache_class_method :zap, :counter => true
|
31
34
|
def self.zap
|
32
35
|
0
|
33
36
|
end
|
37
|
+
|
38
|
+
attr_accessor :z
|
39
|
+
def zang
|
40
|
+
self.z ||= 1
|
41
|
+
self.z += 1
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
cache_method :zang
|
45
|
+
|
46
|
+
cache_method :pow, :expiry => TEST_EXPIRY
|
47
|
+
def pow(ignored)
|
48
|
+
Time.now
|
49
|
+
end
|
50
|
+
|
51
|
+
attr_accessor :bam_updated_at
|
52
|
+
|
53
|
+
cache_method :bam, :load_validation => lambda {|val, meta|
|
54
|
+
if bam_updated_at
|
55
|
+
meta[:cached_at] > bam_updated_at
|
56
|
+
else
|
57
|
+
true
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
def bam
|
62
|
+
@i ||= 0
|
63
|
+
@i += 1
|
64
|
+
end
|
34
65
|
end
|
35
66
|
|
36
67
|
module Bar
|
@@ -62,13 +93,51 @@ class TestMethodCache < Test::Unit::TestCase
|
|
62
93
|
assert_equal 1, f1
|
63
94
|
assert_equal 3, f2
|
64
95
|
|
65
|
-
|
66
|
-
|
67
|
-
|
96
|
+
assert_equal f1, a.foo(1)
|
97
|
+
assert_not_equal f1, f2
|
98
|
+
assert_equal f2, a.foo(2)
|
68
99
|
|
69
100
|
b = a.bar
|
70
|
-
|
71
|
-
|
101
|
+
assert_equal b, a.bar
|
102
|
+
assert_equal b, a.bar
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'store cached_at when cached locally' do
|
106
|
+
a = Foo.new
|
107
|
+
a.foo(1)
|
108
|
+
|
109
|
+
assert a.method_cached_at(:foo, 1) <= Time.now
|
110
|
+
assert_nil a.method_cached_at(:foo, 2)
|
111
|
+
end
|
112
|
+
|
113
|
+
should 'expire and store expires_at when cached locally' do
|
114
|
+
a = Foo.new
|
115
|
+
t = a.pow(1)
|
116
|
+
|
117
|
+
assert a.method_expires_at(:pow, 1) >= Time.now
|
118
|
+
assert_nil a.method_expires_at(:pow, 2)
|
119
|
+
|
120
|
+
# expire and recalculate
|
121
|
+
sleep TEST_EXPIRY
|
122
|
+
assert_not_equal t, a.pow(1)
|
123
|
+
end
|
124
|
+
|
125
|
+
should 'pass cached_at to load_validation' do
|
126
|
+
a = Foo.new
|
127
|
+
i = a.bam
|
128
|
+
|
129
|
+
assert a.method_cached_at(:bam) <= Time.now
|
130
|
+
|
131
|
+
# should be cached
|
132
|
+
assert_equal i, a.bam
|
133
|
+
|
134
|
+
# should still be cached
|
135
|
+
a.bam_updated_at = Time.now - 100
|
136
|
+
assert_equal i, a.bam
|
137
|
+
|
138
|
+
# should now be invalidated
|
139
|
+
a.bam_updated_at = Time.now + 100
|
140
|
+
assert_not_equal i, a.bam
|
72
141
|
end
|
73
142
|
|
74
143
|
should 'disable method_cache' do
|
@@ -182,4 +251,11 @@ class TestMethodCache < Test::Unit::TestCase
|
|
182
251
|
assert_equal "m|:baz|Foo-#{a_hash}|{:a=3,:b=[5,6],:c=Object-#{o_hash}}|[false,true,{:o=Object-#{o_hash}}]", key
|
183
252
|
end
|
184
253
|
end
|
254
|
+
|
255
|
+
should 'cache nil locally' do
|
256
|
+
a = Foo.new
|
257
|
+
a.zang
|
258
|
+
a.zang
|
259
|
+
assert_equal 2, a.z
|
260
|
+
end
|
185
261
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
3
|
require 'shoulda'
|
4
|
-
require 'mocha'
|
4
|
+
require 'mocha/setup'
|
5
5
|
require 'pp'
|
6
6
|
|
7
7
|
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
@@ -10,4 +10,9 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../cache_version/lib"
|
|
10
10
|
require 'method_cache'
|
11
11
|
|
12
12
|
class Test::Unit::TestCase
|
13
|
+
def start_memcache(port)
|
14
|
+
system("memcached -p #{port} -U 0 -d -P /tmp/memcached_#{port}.pid")
|
15
|
+
sleep 1
|
16
|
+
File.read("/tmp/memcached_#{port}.pid")
|
17
|
+
end
|
13
18
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.6.4
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Balthrop
|
@@ -15,13 +15,85 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2013-07-15 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: shoulda
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mocha
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: dalli
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: activesupport
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 17
|
86
|
+
segments:
|
87
|
+
- 2
|
88
|
+
- 3
|
89
|
+
- 9
|
90
|
+
version: 2.3.9
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: memcache
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
25
97
|
none: false
|
26
98
|
requirements:
|
27
99
|
- - ">="
|
@@ -33,28 +105,34 @@ dependencies:
|
|
33
105
|
- 0
|
34
106
|
version: 1.0.0
|
35
107
|
type: :runtime
|
36
|
-
version_requirements: *
|
108
|
+
version_requirements: *id006
|
37
109
|
description: Simple memcache-based memoization library for Ruby
|
38
|
-
email:
|
110
|
+
email:
|
111
|
+
- git@justinbalthrop.com
|
39
112
|
executables: []
|
40
113
|
|
41
114
|
extensions: []
|
42
115
|
|
43
|
-
extra_rdoc_files:
|
44
|
-
|
45
|
-
- README.rdoc
|
116
|
+
extra_rdoc_files: []
|
117
|
+
|
46
118
|
files:
|
119
|
+
- .gitignore
|
120
|
+
- .rbenv-gemsets
|
121
|
+
- .rbenv-version
|
122
|
+
- Gemfile
|
47
123
|
- LICENSE
|
48
124
|
- README.rdoc
|
49
125
|
- Rakefile
|
50
|
-
- VERSION
|
126
|
+
- VERSION
|
51
127
|
- lib/method_cache.rb
|
128
|
+
- lib/method_cache/local_cache.rb
|
52
129
|
- lib/method_cache/proxy.rb
|
53
130
|
- method_cache.gemspec
|
131
|
+
- test/method_cache_remote_test.rb
|
54
132
|
- test/method_cache_test.rb
|
55
133
|
- test/test_helper.rb
|
56
134
|
has_rdoc: true
|
57
|
-
homepage:
|
135
|
+
homepage: https://github.com/ninjudd/method_cache
|
58
136
|
licenses: []
|
59
137
|
|
60
138
|
post_install_message:
|
@@ -87,5 +165,7 @@ rubygems_version: 1.5.2
|
|
87
165
|
signing_key:
|
88
166
|
specification_version: 3
|
89
167
|
summary: Simple memcache-based memoization library for Ruby
|
90
|
-
test_files:
|
91
|
-
|
168
|
+
test_files:
|
169
|
+
- test/method_cache_remote_test.rb
|
170
|
+
- test/method_cache_test.rb
|
171
|
+
- test/test_helper.rb
|