AdoccaMemcache 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,15 +2,17 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
- #require './lib/adocca_memcache.rb'
5
+ require './lib/adocca_memcache.rb'
6
+ require 'cgi'
6
7
 
7
- Hoe.new('AdoccaMemcache', '0.1.11') do |p|
8
+ Hoe.new('AdoccaMemcache', '0.1.12') do |p|
8
9
  p.rubyforge_name = 'adocca-plugins'
9
10
  p.author = 'adocca Entertainment AB'
10
11
  p.summary = 'A client library to simplify using memcached with Ruby on Rails projects.'
11
12
  p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
12
13
  p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
13
14
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.email = 'developers@adocca.com'
14
16
  end
15
17
 
16
18
  # vim: syntax=Ruby
@@ -2,6 +2,7 @@ require 'socket'
2
2
  require 'digest/sha1'
3
3
  require 'timeout'
4
4
  require 'monitor'
5
+ require 'forwardable'
5
6
 
6
7
  module Adocca
7
8
 
@@ -1,3 +1,17 @@
1
+
2
+ module ActiveRecord
3
+ class Base
4
+ end
5
+ end
6
+ module ActionView
7
+ class Base
8
+ end
9
+ end
10
+ module ActionController
11
+ class Base
12
+ end
13
+ end
14
+
1
15
  module MemcacheMemoize
2
16
 
3
17
  # The following is used to cache, using memcache, the results of executing a code block.
@@ -1,15 +1,18 @@
1
-
2
1
  gem 'actionpack'
3
-
4
- class CGI::Session::MemCacheStore
5
- def restore
6
- begin
7
- @session_data = @cache[@session_key]
8
- @session_data = {} if @session_data == :MemCache_no_such_entry
9
- rescue
10
- @session_data = {}
2
+ class CGI
3
+ class Session
4
+ class MemCacheStore
5
+ def restore
6
+ begin
7
+ @session_data = @cache[@session_key]
8
+ @session_data = {} if @session_data == :MemCache_no_such_entry
9
+ rescue Exception => e
10
+ RAILS_DEFAULT_LOGGER.warn("got #{e} when trying to restore session")
11
+ @session_data = {}
12
+ end
13
+ @session_data
14
+ end
11
15
  end
12
- @session_data
13
16
  end
14
17
  end
15
18
 
@@ -0,0 +1,78 @@
1
+
2
+ require 'test/unit'
3
+ require 'rubygems'
4
+
5
+ class TestMemcache < Test::Unit::TestCase
6
+
7
+ def get_cache_instance
8
+ cache = Adocca::MemCache.new :namespace => 'caffeinetest'
9
+ cache.servers = ["localhost:11211"]
10
+ return cache
11
+ end
12
+
13
+ def setup
14
+ @cache = get_cache_instance
15
+ @cache.flush
16
+ end
17
+
18
+ # def teardown
19
+ # end
20
+
21
+ def test_basic
22
+ # ruby value
23
+ @cache.set "foo", :somevalue
24
+ assert_equal :somevalue, @cache.get("foo")
25
+
26
+ # MemCache#check
27
+ assert_equal true, @cache.check("foo")
28
+ @cache.delete "foo"
29
+ assert_equal false, @cache.check("foo")
30
+
31
+ # integer value
32
+ @cache.set "foo2", 100
33
+ assert_equal 100, @cache.get("foo2")
34
+ end
35
+
36
+ def test_multi_key
37
+ @cache.set "burK", "bajs"
38
+ @cache.set "bork", "kiss"
39
+ @cache.set "hehu", "hoj"
40
+ assert_equal(["bajs","kiss","hoj"], @cache.get("burK", "bork", "hehu"))
41
+ @cache.set ["2","4","0","1"], "bingo"
42
+ @cache.set ["4","4","0","11"], "was a dog"
43
+ assert_equal(["bingo","was a dog"], @cache.get(["2","4","0","1"], ["4","4","0","11"]))
44
+ end
45
+
46
+ def test_namespaces
47
+ @cache.set ["ns1", "ns2", "ns3", "item"], :somevalue
48
+ @cache.set ["ns1", "ns2", "item2"], :othervalue
49
+ @cache.set ["ns1", "item3"], :yetanothervalue
50
+ @cache.set ["ns1", "item4"], :lastvalue
51
+ assert_equal :somevalue, @cache.get(["ns1", "ns2", "ns3", "item"])
52
+ @cache.invalidate_namespace ["ns1", "ns2", "ns3"]
53
+ assert_equal(:MemCache_no_such_entry, @cache.get(["ns1", "ns2", "ns3", "item"]))
54
+ assert_equal :othervalue, @cache.get(["ns1", "ns2", "item2"])
55
+ @cache.set ["ns1", "ns2", "ns3", "item"], :somevalue
56
+ assert_equal :somevalue, @cache.get(["ns1", "ns2", "ns3", "item"])
57
+ @cache.invalidate_namespace ["ns1", "ns2"]
58
+ assert_equal(:MemCache_no_such_entry, @cache.get(["ns1", "ns2", "ns3", "item"]))
59
+ assert_equal :yetanothervalue, @cache.get(["ns1", "item3"])
60
+ assert_equal :lastvalue, @cache.get(["ns1", "item4"])
61
+ @cache.invalidate_namespace ["ns1"]
62
+ assert_equal(:MemCache_no_such_entry, @cache.get(["ns1", "item3"]))
63
+ assert_equal(:MemCache_no_such_entry, @cache.get(["ns1", "item4"]))
64
+ end
65
+
66
+ def test_lock
67
+ assert @cache.lock("testlock", :timeout => 10)
68
+ cache2 = get_cache_instance
69
+ assert !cache2.lock("testlock", :timeout => 2) # will block
70
+ @cache.unlock "testlock"
71
+ assert_not_nil cache2.lock("testlock")
72
+ cache2.unlock "testlock"
73
+
74
+ assert @cache.lock("testlock")
75
+ assert_raises(Adocca::MemCacheError) { cache2.synchronize("testlock", :timeout => 2) { sleep(1) } }
76
+ @cache.unlock "testlock"
77
+ end
78
+ end
metadata CHANGED
@@ -1,33 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: AdoccaMemcache
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.11
7
- date: 2007-06-01 00:00:00 +02:00
8
- summary: A client library to simplify using memcached with Ruby on Rails projects.
9
- require_paths:
10
- - lib
11
- email: ryand-ruby@zenspider.com
12
- homepage: " by Adocca AB"
13
- rubyforge_project: adocca-plugins
14
- description: "Based on memcache-client by <a href=\"http://dev.robotcoop.com/\">robotcoop</a>. We started out with their code, but ended up with an almost complete rewrite after having added code for our own needs and requirements. Apologies for not doing proper contributions to their project instead of building our own, but we are limited by commercial requirements rather than open source idealism. == FEATURES/PROBLEMS: * FIX (list of features or problems) == SYNOPSYS:"
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.1.12
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - adocca Entertainment AB
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-27 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.3
23
+ version:
24
+ description: "Based on memcache-client by <a href=\"http://dev.robotcoop.com/\">robotcoop</a>. We started out with their code, but ended up with an almost complete rewrite after having added code for our own needs and requirements. Apologies for not doing proper contributions to their project instead of building our own, but we are limited by commercial requirements rather than open source idealism. == FEATURES/PROBLEMS: * FIX (list of features or problems) == SYNOPSYS:"
25
+ email: developers@adocca.com
26
+ executables:
27
+ - adocca_memcache
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
31
34
  files:
32
35
  - History.txt
33
36
  - Manifest.txt
@@ -40,25 +43,32 @@ files:
40
43
  - lib/am_memcache_store.rb
41
44
  - lib/am_memcache_memoize.rb
42
45
  - test/test_adocca_memcache.rb
43
- test_files:
44
- - test/test_adocca_memcache.rb
45
- rdoc_options: []
46
-
47
- extra_rdoc_files: []
48
-
49
- executables:
50
- - adocca_memcache
51
- extensions: []
52
-
46
+ has_rdoc: true
47
+ homepage: " by Adocca AB"
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --main
51
+ - README.txt
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
53
66
  requirements: []
54
67
 
55
- dependencies:
56
- - !ruby/object:Gem::Dependency
57
- name: hoe
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Version::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 1.2.0
64
- version:
68
+ rubyforge_project: adocca-plugins
69
+ rubygems_version: 1.1.1
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: A client library to simplify using memcached with Ruby on Rails projects.
73
+ test_files:
74
+ - test/test_adocca_memcache.rb