memcachepod 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/lib/memcachepod.rb +1 -0
- data/lib/memcachepod/client.rb +38 -2
- data/lib/memcachepod/memory.rb +34 -7
- data/lib/memcachepod/memory_entry.rb +0 -4
- data/lib/memcachepod/version.rb +1 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4be8f4badcaed7a07fa70ba6e6a9b4331b55e85
|
4
|
+
data.tar.gz: 7ee6cf0f4ffd5c6808051026d8b764697c4dfc13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59969500da2aba676ac51d783e8c58d675c8d497148ba7be3c67f5f52f8933f0f294d348e3a97a4e1f2faa7ac8c0ada8d2170790f928977967e520a050ab27a3
|
7
|
+
data.tar.gz: 9fb4c55d7f262ded596c4bdba7a189026534dd9c4430e3f6237dc0c4a325833411ec87f836ad7736b2f0ce0f17acaa638e8e4c3ab87e2c770aca55c2434867bb
|
data/Gemfile
CHANGED
data/lib/memcachepod.rb
CHANGED
data/lib/memcachepod/client.rb
CHANGED
@@ -18,6 +18,7 @@ module MemcachePod
|
|
18
18
|
@options[:expires_in] = 0
|
19
19
|
@options[:threadsafe] = true
|
20
20
|
@options[:namespace] = ''
|
21
|
+
@options[:max_memory] = 64*1024*1024 # same as memcached
|
21
22
|
|
22
23
|
if options.has_key?(:expires_in)
|
23
24
|
@options[:expires_in] = options[:expires_in]
|
@@ -28,8 +29,11 @@ module MemcachePod
|
|
28
29
|
if options.has_key?(:namespace)
|
29
30
|
@options[:namespace] = options[:namespace]
|
30
31
|
end
|
32
|
+
if options.has_key?(:max_memory)
|
33
|
+
@options[:max_memory] = options[:max_memory]
|
34
|
+
end
|
31
35
|
|
32
|
-
@memory = Memory.new
|
36
|
+
@memory = Memory.new(@options[:max_memory])
|
33
37
|
end
|
34
38
|
|
35
39
|
def get(key, options=nil)
|
@@ -52,7 +56,7 @@ module MemcachePod
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def delete(key)
|
55
|
-
|
59
|
+
@memory.delete(key)
|
56
60
|
end
|
57
61
|
|
58
62
|
def append(key, value)
|
@@ -63,6 +67,34 @@ module MemcachePod
|
|
63
67
|
raise NotImplementedError.new("not implemented prepend()")
|
64
68
|
end
|
65
69
|
|
70
|
+
def incr(key, amt=1, ttl=nil, default=nil)
|
71
|
+
raise NotImplementedError.new("not implemented incr()")
|
72
|
+
end
|
73
|
+
|
74
|
+
def decr(key, amt=1, ttl=nil, default=nil)
|
75
|
+
raise NotImplementedError.new("not implemented decr()")
|
76
|
+
end
|
77
|
+
|
78
|
+
def touch(key, ttl=nil)
|
79
|
+
raise NotImplementedError.new("not implemented touch()")
|
80
|
+
end
|
81
|
+
|
82
|
+
def stats(type=nil)
|
83
|
+
raise NotImplementedError.new("not implemented stats()")
|
84
|
+
end
|
85
|
+
|
86
|
+
def reset_stats
|
87
|
+
raise NotImplementedError.new("not implemented reset_stats()")
|
88
|
+
end
|
89
|
+
|
90
|
+
def alive!
|
91
|
+
raise NotImplementedError.new("not implemented alive!()")
|
92
|
+
end
|
93
|
+
|
94
|
+
def version
|
95
|
+
{ "localhost" => MemcachePod::VERSION }
|
96
|
+
end
|
97
|
+
|
66
98
|
def flush(delay=0)
|
67
99
|
@memory.flush()
|
68
100
|
end
|
@@ -77,6 +109,10 @@ module MemcachePod
|
|
77
109
|
return @options
|
78
110
|
end
|
79
111
|
|
112
|
+
def get_memory_usage
|
113
|
+
return @memory.get_memory_usage
|
114
|
+
end
|
115
|
+
|
80
116
|
private
|
81
117
|
|
82
118
|
def validate_key(key)
|
data/lib/memcachepod/memory.rb
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
module MemcachePod
|
5
5
|
class Memory
|
6
6
|
|
7
|
-
def initialize()
|
8
|
-
@
|
7
|
+
def initialize(max_memory)
|
8
|
+
@max_memory = max_memory.to_i
|
9
9
|
@memory_pool = Hash.new
|
10
10
|
end
|
11
11
|
|
@@ -19,6 +19,7 @@ module MemcachePod
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def set(key, value, ttl=0, options=nil)
|
22
|
+
remove_expires()
|
22
23
|
if(@memory_pool.has_key?(key))
|
23
24
|
@memory_pool[key].update(value,ttl)
|
24
25
|
else
|
@@ -26,6 +27,12 @@ module MemcachePod
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
30
|
+
def delete(key)
|
31
|
+
if(@memory_pool.has_key?(key))
|
32
|
+
@memory_pool.delete(key)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
def flush()
|
30
37
|
@memory_pool = Hash.new
|
31
38
|
end
|
@@ -35,20 +42,40 @@ module MemcachePod
|
|
35
42
|
v.get_status
|
36
43
|
}
|
37
44
|
end
|
45
|
+
|
46
|
+
def get_memory_usage
|
47
|
+
total = 0
|
48
|
+
@memory_pool.map {|k,v|
|
49
|
+
total += v.body.size
|
50
|
+
}
|
51
|
+
return total
|
52
|
+
end
|
38
53
|
|
39
54
|
private
|
40
55
|
|
41
56
|
def remove_expires()
|
42
57
|
@memory_pool.each_key{ |key|
|
43
58
|
entry = @memory_pool[key]
|
44
|
-
if
|
45
|
-
|
46
|
-
|
47
|
-
end
|
59
|
+
if entry.expired?
|
60
|
+
@memory_pool.delete(key)
|
61
|
+
#printf( "remove 1, key : %s \n", key )
|
48
62
|
end
|
49
63
|
}
|
64
|
+
|
65
|
+
total = get_memory_usage
|
66
|
+
|
67
|
+
@memory_pool.each_key{ |key|
|
68
|
+
if @max_memory <= total
|
69
|
+
entry = @memory_pool[key]
|
70
|
+
total -= entry.body.size
|
71
|
+
@memory_pool.delete(key)
|
72
|
+
#printf( "remove 2, key : %s \n", key )
|
73
|
+
else
|
74
|
+
break
|
75
|
+
end
|
76
|
+
}
|
77
|
+
|
50
78
|
end
|
51
|
-
|
52
79
|
end
|
53
80
|
end
|
54
81
|
|
data/lib/memcachepod/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memcachepod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kiyoka Nishiyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rdoc
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,7 +24,7 @@ dependencies:
|
|
38
24
|
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '0'
|
41
|
-
description:
|
27
|
+
description: In-process caching library that provide memcached compatible interface.
|
42
28
|
email:
|
43
29
|
- kiyoka@sumibi.org
|
44
30
|
executables: []
|
@@ -77,5 +63,5 @@ rubyforge_project:
|
|
77
63
|
rubygems_version: 2.6.11
|
78
64
|
signing_key:
|
79
65
|
specification_version: 4
|
80
|
-
summary:
|
66
|
+
summary: In-process caching library that provide memcached compatible interface.
|
81
67
|
test_files: []
|