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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63e4f41dfa41db87514ab48a0177512aa40ef64a
4
- data.tar.gz: 1e21e5f83b81a4dfaf1a4d47f86b4e0c40c5a116
3
+ metadata.gz: b4be8f4badcaed7a07fa70ba6e6a9b4331b55e85
4
+ data.tar.gz: 7ee6cf0f4ffd5c6808051026d8b764697c4dfc13
5
5
  SHA512:
6
- metadata.gz: dbc36eaaad05a2409a72d49000f42be594174d5f1ffb8626468e56d9824ed16e8ae53de01a2b62a125af736d3aec0eecdb105a3af0e596b7ebf37ecbb473d1ca
7
- data.tar.gz: f28f1e1bdf3dc95816eb76834c006310bfd0b7b869d90b21b7f841a959191b2cc14b16e86b4da7ce9415551d7fef35aac47ff35475acc31ce63959cd47e6d28b
6
+ metadata.gz: 59969500da2aba676ac51d783e8c58d675c8d497148ba7be3c67f5f52f8933f0f294d348e3a97a4e1f2faa7ac8c0ada8d2170790f928977967e520a050ab27a3
7
+ data.tar.gz: 9fb4c55d7f262ded596c4bdba7a189026534dd9c4430e3f6237dc0c4a325833411ec87f836ad7736b2f0ce0f17acaa638e8e4c3ab87e2c770aca55c2434867bb
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
+ gemspec
2
3
  gem "rspec"
3
4
  gem "rake"
4
5
  gem "simplecov"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'memcachepod/version'
3
4
  require 'memcachepod/memory_entry'
4
5
  require 'memcachepod/memory'
5
6
  require 'memcachepod/client'
@@ -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
- raise NotImplementedError.new("not implemented delete()")
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)
@@ -4,8 +4,8 @@
4
4
  module MemcachePod
5
5
  class Memory
6
6
 
7
- def initialize()
8
- @size = 1024*1024 # bytes
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 not entry.reference?
45
- if entry.expired?
46
- @memory_pool.delete(key)
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
 
@@ -22,10 +22,6 @@ module MemcachePod
22
22
  return @body
23
23
  end
24
24
 
25
- def reference?()
26
- return @refernece
27
- end
28
-
29
25
  def expired?()
30
26
  if 0 < @expires_in
31
27
  now = Time.now.to_i #second
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module MemcachePod
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
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.1
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-19 00:00:00.000000000 Z
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: []