tokyo_cache_cow 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +3 -2
- data/lib/tokyo_cache_cow/cache/base.rb +6 -0
- data/lib/tokyo_cache_cow/cache/file_memcache.rb +4 -0
- data/lib/tokyo_cache_cow/cache/hash_memcache.rb +4 -0
- data/lib/tokyo_cache_cow/cache/tokyo_cabinet_memcache.rb +6 -0
- data/lib/tokyo_cache_cow/server.rb +15 -7
- data/spec/cache_spec.rb +18 -9
- data/spec/server_spec.rb +2 -2
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -10,6 +10,12 @@ class TokyoCacheCow
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
def average_match(match)
|
14
|
+
average_keys = get_match(match)
|
15
|
+
values = average_keys.map{|ak| get(ak)}.map{|v| Integer(v[:value]) rescue nil}.compact
|
16
|
+
values.inject(0.0) { |sum, el| sum + el } / values.size
|
17
|
+
end
|
18
|
+
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
@@ -43,6 +43,10 @@ class TokyoCacheCow
|
|
43
43
|
FileUtils.rm Dir.glob(File.join(@path, "*#{CGI.escape(key)}*"))
|
44
44
|
end
|
45
45
|
|
46
|
+
def get_match(key)
|
47
|
+
Dir.glob(File.join(@path, "*#{CGI.escape(key)}*")).map{|d| d}.map{|f| File.basename(f)}
|
48
|
+
end
|
49
|
+
|
46
50
|
def replace(key, value, options = {})
|
47
51
|
set(key, value, options) if File.exists?(path_for_key(key))
|
48
52
|
end
|
@@ -38,6 +38,10 @@ class TokyoCacheCow
|
|
38
38
|
@cache.delete_if{ |key, value| key.index(key) }
|
39
39
|
end
|
40
40
|
|
41
|
+
def get_match(match)
|
42
|
+
@cache.keys.select{ |key| key.index(key) }
|
43
|
+
end
|
44
|
+
|
41
45
|
def replace(key, value, options = {})
|
42
46
|
set(key, value, options) if @cache.key?(key)
|
43
47
|
end
|
@@ -108,6 +108,12 @@ class TokyoCacheCow
|
|
108
108
|
q.searchout
|
109
109
|
end
|
110
110
|
|
111
|
+
def get_match(match)
|
112
|
+
q = TDBQRY.new(@cache)
|
113
|
+
q.addcond('', TDBQRY::QCSTRINC, match)
|
114
|
+
q.search
|
115
|
+
end
|
116
|
+
|
111
117
|
def initialize(options = {})
|
112
118
|
@cache = TDB::new # hash database
|
113
119
|
raise('must supply file') unless options[:file]
|
@@ -101,15 +101,23 @@ class TokyoCacheCow
|
|
101
101
|
keys = args.split(/\s+/)
|
102
102
|
keys.each do |k|
|
103
103
|
next unless validate_key(k)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
|
105
|
+
puts "in get!"
|
106
|
+
|
107
|
+
if k =~ /^average-/
|
108
|
+
puts "matched!!"
|
109
|
+
else
|
110
|
+
if data = @cache.get(k)
|
111
|
+
if command == 'get'
|
112
|
+
send_data(GetValueReply % [k, data[:flags], data[:value].size])
|
113
|
+
else
|
114
|
+
send_data(CasValueReply % [k, data[:flags], data[:value].size, data[:value].hash])
|
115
|
+
end
|
116
|
+
send_data(data[:value])
|
117
|
+
send_data(Terminator)
|
109
118
|
end
|
110
|
-
send_data(data[:value])
|
111
|
-
send_data(Terminator)
|
112
119
|
end
|
120
|
+
|
113
121
|
end
|
114
122
|
send_data(EndReply)
|
115
123
|
when 'set'
|
data/spec/cache_spec.rb
CHANGED
@@ -20,6 +20,15 @@ require 'lib/tokyo_cache_cow/cache'
|
|
20
20
|
cache.get('added_key')[:value].should == 'zig'
|
21
21
|
end
|
22
22
|
|
23
|
+
it "should average" do
|
24
|
+
cache.set("session1-value1","12")
|
25
|
+
cache.set("session1-value2","11")
|
26
|
+
cache.set("session1-value3","13")
|
27
|
+
cache.set("session1-value4","10")
|
28
|
+
cache.set("session1-value5","14")
|
29
|
+
cache.average_match('session1').should == 12
|
30
|
+
end
|
31
|
+
|
23
32
|
it "should put & get" do
|
24
33
|
100.times do |i|
|
25
34
|
cache.set("/blog/show/#{i}","this is a big ol' blog post!!! #{i}")
|
@@ -29,14 +38,14 @@ require 'lib/tokyo_cache_cow/cache'
|
|
29
38
|
cache.get("/blog/show/#{i}")[:value].should == "this is a big ol' blog post!!! #{i}"
|
30
39
|
end
|
31
40
|
end
|
32
|
-
|
41
|
+
|
33
42
|
it "should delete" do
|
34
43
|
cache.set("key-set-123","you should never see me")
|
35
44
|
cache.get("key-set-123")[:value].should == "you should never see me"
|
36
45
|
cache.delete("key-set-123")
|
37
46
|
cache.get("key-set-123").should == nil
|
38
47
|
end
|
39
|
-
|
48
|
+
|
40
49
|
it "should delete (with expiry)" do
|
41
50
|
cache.set('delete-with-expiry', 'hillbillies')
|
42
51
|
cache.get('delete-with-expiry')[:value].should == 'hillbillies'
|
@@ -49,7 +58,7 @@ require 'lib/tokyo_cache_cow/cache'
|
|
49
58
|
cache.set('delete-with-expiry', 'more hillbillies')
|
50
59
|
cache.get('delete-with-expiry')[:value].should == 'more hillbillies'
|
51
60
|
end
|
52
|
-
|
61
|
+
|
53
62
|
it "should delete (with expiry) and set again" do
|
54
63
|
cache.set('delete-with-expiry', 'hillbillies')
|
55
64
|
cache.get('delete-with-expiry')[:value].should == 'hillbillies'
|
@@ -60,7 +69,7 @@ require 'lib/tokyo_cache_cow/cache'
|
|
60
69
|
sleep(5)
|
61
70
|
cache.get('delete-with-expiry')[:value].should == 'more hillbillies'
|
62
71
|
end
|
63
|
-
|
72
|
+
|
64
73
|
it "should delete_match" do
|
65
74
|
100.times do
|
66
75
|
cache.set("asd/qwe/zxc/10","you should never see me")
|
@@ -114,13 +123,13 @@ require 'lib/tokyo_cache_cow/cache'
|
|
114
123
|
cache.get("asd/qwe/zxc/121").should == nil
|
115
124
|
end
|
116
125
|
end
|
117
|
-
|
126
|
+
|
118
127
|
it "should expire" do
|
119
128
|
cache.set("expiring key","you should never see me", :expires => 1)
|
120
129
|
sleep(3)
|
121
130
|
cache.get("expiring key").should == nil
|
122
131
|
end
|
123
|
-
|
132
|
+
|
124
133
|
it "should replace" do
|
125
134
|
cache.replace("replacing-key", "newkey")
|
126
135
|
cache.get("replacing-key").should == nil
|
@@ -128,20 +137,20 @@ require 'lib/tokyo_cache_cow/cache'
|
|
128
137
|
cache.replace("replacing-key", "newkey")
|
129
138
|
cache.get("replacing-key")[:value].should == 'newkey'
|
130
139
|
end
|
131
|
-
|
140
|
+
|
132
141
|
it "should append" do
|
133
142
|
cache.set("appending-key", "test1")
|
134
143
|
cache.get("appending-key")[:value].should == "test1"
|
135
144
|
cache.append("appending-key", "test2")
|
136
145
|
cache.get("appending-key")[:value].should == "test1test2"
|
137
146
|
end
|
138
|
-
|
147
|
+
|
139
148
|
it "should incr" do
|
140
149
|
cache.set("incr-key", 123)
|
141
150
|
cache.incr("incr-key", 20).should == 143
|
142
151
|
cache.get("incr-key")[:value].should == '143'
|
143
152
|
end
|
144
|
-
|
153
|
+
|
145
154
|
it "should decr" do
|
146
155
|
cache.set("decr-key", 123)
|
147
156
|
cache.decr("decr-key", 20).should == 103
|
data/spec/server_spec.rb
CHANGED
@@ -30,9 +30,8 @@ describe 'memcache server' do
|
|
30
30
|
|
31
31
|
after(:all) do
|
32
32
|
Process.kill('INT', @pid)
|
33
|
+
sleep(1)
|
33
34
|
end
|
34
|
-
|
35
|
-
|
36
35
|
end
|
37
36
|
|
38
37
|
describe 'memcache server with special delete support' do
|
@@ -64,6 +63,7 @@ describe 'memcache server with special delete support' do
|
|
64
63
|
|
65
64
|
after(:all) do
|
66
65
|
Process.kill('INT', @pid)
|
66
|
+
sleep(1)
|
67
67
|
end
|
68
68
|
|
69
69
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tokyo_cache_cow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-12 00:00:00 -05:00
|
13
13
|
default_executable: tokyo_cache_cow
|
14
14
|
dependencies: []
|
15
15
|
|