CacheGorilla 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.0.2 2010-07-10
2
+ * Added ability to expire memcache before Redis
3
+
1
4
  === 0.0.1 2010-07-10
2
5
 
3
6
  * 1 major enhancement:
data/README.rdoc CHANGED
@@ -1,9 +1,9 @@
1
1
  = CacheGorilla
2
2
 
3
- http://www.animalpictures1.com/data/media/65/gorilla-7.jpg
4
-
5
3
  * http://github.com/timrosenblatt/CacheGorilla
6
4
 
5
+ http://www.animalpictures1.com/data/media/65/gorilla-7.jpg
6
+
7
7
  == DESCRIPTION:
8
8
 
9
9
  Let's say you've got a MongoDB server, being used as a key-value store for an app being served by three sticky-load-balanced web servers. Running an instance of memcached will speed up repeated reads.
@@ -12,10 +12,6 @@ Let's say you've got a MongoDB server, being used as a key-value store for an ap
12
12
 
13
13
  This speeds up MongoDB by using antimatter and solar rays.
14
14
 
15
- == FEATURES/PROBLEMS:
16
-
17
- * FIX (list of features or problems)
18
-
19
15
  == SYNOPSIS:
20
16
 
21
17
  include CacheGorilla
data/Rakefile CHANGED
@@ -11,10 +11,10 @@ Hoe.plugin :newgem
11
11
  # Generate all the Rake tasks
12
12
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
13
  $hoe = Hoe.spec 'CacheGorilla' do
14
- self.developer 'Tim', 'Rosenblatt'
14
+ self.developer 'Tim Rosenblatt', 'rubygems@timrosenblatt.com'
15
15
  self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
- # self.extra_deps = [['activesupport','>= 2.0.2']]
17
+ self.extra_deps = [['mongo','>= 1.0.0'], ['memcached', '>= 0.19.5']]
18
18
 
19
19
  end
20
20
 
data/lib/CacheGorilla.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module CacheGorilla
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
 
7
7
  begin
8
8
  require "memcached"
@@ -35,10 +35,13 @@ module CacheGorilla
35
35
  :port => ENV['MONGO_RUBY_DRIVER_PORT'] || 27017,
36
36
  :db => 'cache',
37
37
  :collection => 'cache',
38
- :server => 'localhost'
38
+ :server => 'localhost',
39
+ :mongo_pool_size => 5,
40
+ :mongo_timeout => 5,
41
+ :memcache_default_expire => nil
39
42
  }.update(options)
40
43
 
41
- @mongo_connection = Mongo::Connection.new(@options[:host], @options[:port], :pool_size => 5, :timeout => 5)
44
+ @mongo_connection = Mongo::Connection.new(@options[:host], @options[:port], :pool_size => @options[:mongo_pool_size], :timeout => @options[:mongo_timeout])
42
45
  @mongo_collection = @mongo_connection.db(@options[:db]).collection(@options[:collection])
43
46
 
44
47
  @memcache = MemCache.new(options[:server], @options)
@@ -58,7 +61,7 @@ module CacheGorilla
58
61
  res = nil if res && res['expires'] && Time.now > res['expires']
59
62
 
60
63
  if res
61
- args = [res['_id'], res['data'], res['expires']].compact
64
+ args = [res['_id'], res['data'], @options[:memcache_default_expire] || res['expires']].compact
62
65
  @memcache.set(*args)
63
66
  end
64
67
 
@@ -85,7 +88,7 @@ module CacheGorilla
85
88
  @mongo_collection.update({ '_id' => key }, { '_id' => key, 'data' => value, 'expires' => exp }, { :upsert => true }) # upsert is the best technical term ever.
86
89
 
87
90
  unless options.has_key?(:bypass_memcache)
88
- args = [key, value, options[:expires_in]].compact
91
+ args = [key, value, options[:expires_in] || @options[:memcache_default_expire]].compact
89
92
  @memcache.set(*args)
90
93
  end
91
94
 
@@ -99,4 +99,30 @@ describe "CacheGorilla" do
99
99
  @cg.memcache_get("key").should be_nil
100
100
  @cg["key"].should == "value"
101
101
  end
102
+
103
+ it "expires memcache before mongo" do
104
+ @cg = CacheGorilla.new(:db => "cache_gorilla_test", :memcache_default_expire => 2)
105
+ @cg["key"] = "value"
106
+ sleep(5)
107
+ @cg.memcache_get("key").should be_nil
108
+ @cg["key"].should == "value"
109
+ end
110
+
111
+ it "expires memcache before mongo when filling the cache during a miss" do
112
+ @cg = CacheGorilla.new(:db => "cache_gorilla_test", :memcache_default_expire => 2)
113
+ @cg["key"] = "value"
114
+ sleep(5)
115
+ @cg.memcache_get("key").should be_nil
116
+ @cg["key"].should == "value"
117
+ sleep(5)
118
+ @cg.memcache_get("key").should be_nil
119
+ @cg["key"].should == "value"
120
+ end
121
+
122
+ it "respects overridden memcache expiration times" do
123
+ @cg = CacheGorilla.new(:db => "cache_gorilla_test", :memcache_default_expire => 2)
124
+ @cg.store("key", "value", :expires_in => 100)
125
+ sleep(5)
126
+ @cg.memcache_get("key").should == "value"
127
+ end
102
128
  end
metadata CHANGED
@@ -5,22 +5,50 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
- - Tim
12
+ - Tim Rosenblatt
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-10 00:00:00 -04:00
17
+ date: 2010-07-11 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rubyforge
21
+ name: mongo
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: memcached
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 19
44
+ - 5
45
+ version: 0.19.5
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rubyforge
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
24
52
  requirements:
25
53
  - - ">="
26
54
  - !ruby/object:Gem::Version
@@ -30,11 +58,11 @@ dependencies:
30
58
  - 4
31
59
  version: 2.0.4
32
60
  type: :development
33
- version_requirements: *id001
61
+ version_requirements: *id003
34
62
  - !ruby/object:Gem::Dependency
35
63
  name: hoe
36
64
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
65
+ requirement: &id004 !ruby/object:Gem::Requirement
38
66
  requirements:
39
67
  - - ">="
40
68
  - !ruby/object:Gem::Version
@@ -44,10 +72,10 @@ dependencies:
44
72
  - 1
45
73
  version: 2.6.1
46
74
  type: :development
47
- version_requirements: *id002
75
+ version_requirements: *id004
48
76
  description: Let's say you've got a MongoDB server, being used as a key-value store for an app being served by three sticky-load-balanced web servers. Running an instance of memcached will speed up repeated reads.
49
77
  email:
50
- - Rosenblatt
78
+ - rubygems@timrosenblatt.com
51
79
  executables: []
52
80
 
53
81
  extensions: []
@@ -71,7 +99,7 @@ files:
71
99
  - spec/spec_helper.rb
72
100
  - tasks/rspec.rake
73
101
  has_rdoc: true
74
- homepage: http://www.animalpictures1.com/data/media/65/gorilla-7.jpg
102
+ homepage: http://github.com/timrosenblatt/CacheGorilla
75
103
  licenses: []
76
104
 
77
105
  post_install_message: PostInstall.txt