tokyo_cache_cow 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -3
- data/Rakefile +1 -0
- data/VERSION.yml +2 -2
- data/lib/tokyo_cache_cow/cache.rb +4 -6
- data/lib/tokyo_cache_cow/cache/base.rb +18 -8
- data/lib/tokyo_cache_cow/cache/file_memcache.rb +2 -2
- data/lib/tokyo_cache_cow/cache/tokyo_cabinet_memcache.rb +2 -2
- data/lib/tokyo_cache_cow/runner.rb +8 -3
- data/lib/tokyo_cache_cow/server.rb +4 -4
- data/spec/cache_spec.rb +1 -1
- metadata +13 -5
- data/lib/tokyo_cache_cow/providers.rb +0 -13
data/README.rdoc
CHANGED
@@ -62,7 +62,7 @@ But <i>other_key</i> is still peachy.
|
|
62
62
|
|
63
63
|
=== Aggregate functions
|
64
64
|
|
65
|
-
You can invoke aggregates by using the
|
65
|
+
You can invoke aggregates by using the functions <tt>avg()</tt>, <tt>count()</tt>, <tt>sum()</tt>, <tt>min()</tt> and <tt>max()</tt>.
|
66
66
|
|
67
67
|
>> Rails.cache.write('hello1', '1')
|
68
68
|
=> true
|
@@ -70,9 +70,9 @@ You can invoke aggregates by using the prefixes <tt>average-</tt>, <tt>count-</t
|
|
70
70
|
=> true
|
71
71
|
>> Rails.cache.write('hello3', '3')
|
72
72
|
=> true
|
73
|
-
>> Rails.cache.read('
|
73
|
+
>> Rails.cache.read('avg(hello)')
|
74
74
|
=> "2.0"
|
75
|
-
>> Rails.cache.read('sum
|
75
|
+
>> Rails.cache.read('sum(hello)')
|
76
76
|
=> "6.0"
|
77
77
|
|
78
78
|
|
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__))
|
2
|
-
|
3
1
|
class TokyoCacheCow
|
4
2
|
class Cache
|
5
|
-
self.autoload :Base, 'cache
|
6
|
-
self.autoload :FileMemcache, 'cache
|
7
|
-
self.autoload :TokyoCabinetMemcache, 'cache
|
8
|
-
self.autoload :HashMemcache, 'cache
|
3
|
+
self.autoload :Base, File.join('tokyo_cache_cow', 'cache', 'base')
|
4
|
+
self.autoload :FileMemcache, File.join('tokyo_cache_cow', 'cache', 'file_memcache')
|
5
|
+
self.autoload :TokyoCabinetMemcache, File.join('tokyo_cache_cow', 'cache', 'tokyo_cabinet_memcache')
|
6
|
+
self.autoload :HashMemcache, File.join('tokyo_cache_cow', 'cache', 'hash_memcache')
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
@@ -2,6 +2,16 @@ class TokyoCacheCow
|
|
2
2
|
class Cache
|
3
3
|
class Base
|
4
4
|
|
5
|
+
attr_accessor :marshalling_enabled
|
6
|
+
|
7
|
+
def marshal(val)
|
8
|
+
marshalling_enabled ? Marshal.dump(val) : val
|
9
|
+
end
|
10
|
+
|
11
|
+
def unmarshal(val)
|
12
|
+
marshalling_enabled ? Marshal.load(val) : val
|
13
|
+
end
|
14
|
+
|
5
15
|
def process_time(time)
|
6
16
|
time = case time
|
7
17
|
when 0, nil: 0
|
@@ -9,35 +19,35 @@ class TokyoCacheCow
|
|
9
19
|
else time
|
10
20
|
end
|
11
21
|
end
|
12
|
-
|
13
|
-
def
|
22
|
+
|
23
|
+
def avg_match(match)
|
14
24
|
values = numeric_values_match(match)
|
15
|
-
values.inject(0.0) { |sum, el| sum + el } / values.size
|
25
|
+
marshal(values.inject(0.0) { |sum, el| sum + el } / values.size)
|
16
26
|
end
|
17
27
|
|
18
28
|
def sum_match(match)
|
19
29
|
values = numeric_values_match(match)
|
20
|
-
values.inject(0.0) { |sum, el| sum + el }
|
30
|
+
marshal(values.inject(0.0) { |sum, el| sum + el })
|
21
31
|
end
|
22
32
|
|
23
33
|
def count_match(match)
|
24
34
|
values = numeric_values_match(match)
|
25
|
-
values.size
|
35
|
+
marshal(values.size)
|
26
36
|
end
|
27
37
|
|
28
38
|
def min_match(match)
|
29
39
|
values = numeric_values_match(match)
|
30
|
-
values.min
|
40
|
+
marshal(values.min)
|
31
41
|
end
|
32
42
|
|
33
43
|
def max_match(match)
|
34
44
|
values = numeric_values_match(match)
|
35
|
-
values.max
|
45
|
+
marshal(values.max)
|
36
46
|
end
|
37
47
|
|
38
48
|
def numeric_values_match(match)
|
39
49
|
numeric_keys = get_match(match)
|
40
|
-
numeric_keys.map{|ak| get(ak)}.map{|v| Integer(v[:value]) rescue nil}.compact
|
50
|
+
numeric_keys.map{|ak| get(ak)}.map{|v| Integer(unmarshal(v[:value])) rescue nil}.compact
|
41
51
|
end
|
42
52
|
|
43
53
|
end
|
@@ -88,12 +88,12 @@ class TokyoCacheCow
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def get_raw(key)
|
91
|
-
File.exists?(path_for_key(key)) ? YAML::load( File.open( path_for_key(key)
|
91
|
+
File.exists?(path_for_key(key)) ? unmarshal(YAML::load( File.open( path_for_key(key)))) : nil
|
92
92
|
end
|
93
93
|
|
94
94
|
def set_raw(key, data)
|
95
95
|
File.open(path_for_key(key), 'w') do |out|
|
96
|
-
YAML.dump(data, out)
|
96
|
+
YAML.dump(data, marshal(out))
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -28,7 +28,7 @@ class TokyoCacheCow
|
|
28
28
|
delete(key)
|
29
29
|
nil
|
30
30
|
else
|
31
|
-
{ :value => data['value'], :expires => expires, :flags => flags }
|
31
|
+
{ :value => unmarshal(data['value']), :expires => expires, :flags => flags }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -68,7 +68,7 @@ class TokyoCacheCow
|
|
68
68
|
def generate_data_hash(value, options)
|
69
69
|
expires = options[:expires] && options[:expires].to_s || '0'
|
70
70
|
flags = options[:flags] && options[:flags].to_s || '0'
|
71
|
-
{ 'value' => value, 'expires' => process_time(expires), 'flags' => flags }
|
71
|
+
{ 'value' => marshal(value), 'expires' => process_time(expires), 'flags' => flags }
|
72
72
|
end
|
73
73
|
|
74
74
|
def time_expired?(time)
|
@@ -18,7 +18,8 @@ class TokyoCacheCow
|
|
18
18
|
:file => '/tmp/tcc-cache',
|
19
19
|
:pid => '/tmp/tcc.pid',
|
20
20
|
:special_delete_prefix => nil,
|
21
|
-
:daemonize => false
|
21
|
+
:daemonize => false,
|
22
|
+
:marshalling => true
|
22
23
|
}
|
23
24
|
|
24
25
|
parse!
|
@@ -56,13 +57,17 @@ class TokyoCacheCow
|
|
56
57
|
end
|
57
58
|
|
58
59
|
opts.on("-P[OPTIONAL]", "--pid", "Pid file (default: #{options[:pid]})") do |v|
|
59
|
-
options[:pid] =
|
60
|
+
options[:pid] = v
|
60
61
|
end
|
61
62
|
|
62
63
|
opts.on("-m[OPTIONAL]", "--matcher", "Special flag for doing matched deletes (not enabled by default)") do |v|
|
63
64
|
options[:special_delete_char] = v
|
64
65
|
end
|
65
66
|
|
67
|
+
opts.on("-M[=OPTIONAL]", "--marshalling", "Disable marshalling of values") do |v|
|
68
|
+
options[:marshalling] = false
|
69
|
+
end
|
70
|
+
|
66
71
|
opts.on_tail("-h", "--help", "Show this help message.") { puts opts; exit }
|
67
72
|
|
68
73
|
end
|
@@ -79,13 +84,13 @@ class TokyoCacheCow
|
|
79
84
|
parent.const_get(mod)
|
80
85
|
end
|
81
86
|
|
82
|
-
|
83
87
|
address = @options[:address]
|
84
88
|
port = @options[:port]
|
85
89
|
special_delete_char = @options[:special_delete_char]
|
86
90
|
puts "Starting the tokyo cache cow #{address} #{port}"
|
87
91
|
pid = EM.fork_reactor do
|
88
92
|
cache = clazz.new(:file => @options[:file])
|
93
|
+
cache.marshalling_enabled =
|
89
94
|
trap("INT") { EM.stop; puts "\nmoooooooo ya later"; exit(0)}
|
90
95
|
EM.run do
|
91
96
|
EM.start_server(address, port, TokyoCacheCow::Server) do |c|
|
@@ -101,10 +101,10 @@ class TokyoCacheCow
|
|
101
101
|
keys = args.split(/\s+/)
|
102
102
|
keys.each do |k|
|
103
103
|
next unless validate_key(k)
|
104
|
-
if k =~ /^(
|
105
|
-
|
106
|
-
send_data(GetValueReply % [k, "0",
|
107
|
-
send_data(
|
104
|
+
if k =~ /^(avg|sum|count|min|max)\((.*?)\)$/
|
105
|
+
value = @cache.send(:"#{$1}_match", $2).to_s
|
106
|
+
send_data(GetValueReply % [k, "0", value.size])
|
107
|
+
send_data(value)
|
108
108
|
send_data(Terminator)
|
109
109
|
else
|
110
110
|
if data = @cache.get(k)
|
data/spec/cache_spec.rb
CHANGED
@@ -26,7 +26,7 @@ require 'lib/tokyo_cache_cow/cache'
|
|
26
26
|
cache.set("session1-value3","13")
|
27
27
|
cache.set("session1-value4","10")
|
28
28
|
cache.set("session1-value5","14")
|
29
|
-
cache.
|
29
|
+
cache.avg_match('session1').should == 12
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should put & get" do
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-17 00:00:00 -04:00
|
13
13
|
default_executable: tokyo_cache_cow
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eventmachine
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
16
25
|
description: ""
|
17
26
|
email: joshbuddy@gmail.com
|
18
27
|
executables:
|
@@ -32,7 +41,6 @@ files:
|
|
32
41
|
- lib/tokyo_cache_cow/cache/file_memcache.rb
|
33
42
|
- lib/tokyo_cache_cow/cache/hash_memcache.rb
|
34
43
|
- lib/tokyo_cache_cow/cache/tokyo_cabinet_memcache.rb
|
35
|
-
- lib/tokyo_cache_cow/providers.rb
|
36
44
|
- lib/tokyo_cache_cow/runner.rb
|
37
45
|
- lib/tokyo_cache_cow/server.rb
|
38
46
|
- rails/init.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class TokyoCacheCow
|
2
|
-
|
3
|
-
autoload :TokyoCabinetMemcache, 'lib/tokyo_cache_cow/tokyo_cabinet_memcache'
|
4
|
-
|
5
|
-
class Providers
|
6
|
-
|
7
|
-
def self.provide_cache
|
8
|
-
#require 'lib/tokyo_cache_cow/tokyo_cabinet_memcache'
|
9
|
-
@@cache ||= TokyoCacheCow::TokyoCabinetMemcache.new('/tmp/tcc')
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|