itrigga-cache 0.3.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2-p290@itrigga-cache --create
data/Gemfile CHANGED
@@ -5,12 +5,28 @@ source "http://rubygems.org"
5
5
 
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
- gem "memcached"
8
+
9
9
  gem "itrigga-param_fu"
10
+ gem "itrigga-core_ext"
11
+
12
+ gem "bundler", ">= 1.0.0"
10
13
 
14
+ # Add dependencies to develop your gem here.
15
+ # Include everything needed to run rake, tests, features, etc.
11
16
  group :development do
12
17
  gem "rspec", "1.3.0"
13
- gem "bundler", "~> 1.0.0"
18
+ gem "rspec-rails", "1.3.2"
19
+ gem "bundler", ">= 1.0.0"
14
20
  gem "jeweler", "~> 1.6.4"
15
21
  gem "rcov", ">= 0"
22
+ gem "fastercsv", ">= 1.5.4"
23
+ end
24
+
25
+ group :test do
26
+ gem "rspec", "1.3.0"
27
+ gem 'test-unit', '1.2.3' # needed by rspec if using ruby 1.9.X
28
+ gem "rspec-rails", "1.3.2"
29
+ gem "bundler", ">= 1.0.0"
30
+ gem "rcov", ">= 0"
31
+ gem "fastercsv", ">= 1.5.4"
16
32
  end
@@ -1,24 +1,36 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ fastercsv (1.5.4)
4
5
  git (1.2.5)
5
- itrigga-param_fu (0.0.1)
6
+ hoe (2.16.0)
7
+ rake (~> 0.8)
8
+ itrigga-core_ext (0.3.0)
9
+ itrigga-param_fu (0.4.2)
6
10
  jeweler (1.6.4)
7
11
  bundler (~> 1.0)
8
12
  git (>= 1.2.5)
9
13
  rake
10
- memcached (1.3.5)
11
- rake (0.8.7)
12
- rcov (0.9.11)
14
+ rack (1.4.1)
15
+ rake (0.9.2.2)
16
+ rcov (1.0.0)
13
17
  rspec (1.3.0)
18
+ rspec-rails (1.3.2)
19
+ rack (>= 1.0.0)
20
+ rspec (>= 1.3.0)
21
+ test-unit (1.2.3)
22
+ hoe (>= 1.5.1)
14
23
 
15
24
  PLATFORMS
16
25
  ruby
17
26
 
18
27
  DEPENDENCIES
19
- bundler (~> 1.0.0)
28
+ bundler (>= 1.0.0)
29
+ fastercsv (>= 1.5.4)
30
+ itrigga-core_ext
20
31
  itrigga-param_fu
21
32
  jeweler (~> 1.6.4)
22
- memcached
23
33
  rcov
24
34
  rspec (= 1.3.0)
35
+ rspec-rails (= 1.3.2)
36
+ test-unit (= 1.2.3)
data/Rakefile CHANGED
@@ -27,6 +27,7 @@ Jeweler::Tasks.new do |gem|
27
27
  end
28
28
  Jeweler::RubygemsDotOrgTasks.new
29
29
 
30
+
30
31
  require 'spec/version'
31
32
  require 'spec/rake/spectask'
32
33
  require 'spec/ruby'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 1.1.0
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "itrigga-cache"
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Al Davidson", "Anson Kelly"]
12
+ s.date = "2011-12-03"
13
+ s.description = "Wraps memcached with helpful methods"
14
+ s.email = "support@itrigga.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/itrigga/cache.rb",
29
+ "lib/itrigga/cache/cache.rb",
30
+ "lib/itrigga/cache/filecache.rb",
31
+ "lib/itrigga/cache/memcache.rb",
32
+ "spec/filecache_spec.rb",
33
+ "spec/itrigga-cache_spec.rb",
34
+ "spec/memcache_spec.rb",
35
+ "spec/spec.opts",
36
+ "spec/spec_helper.rb",
37
+ "support/singleton_reset.rb"
38
+ ]
39
+ s.homepage = "http://gemcutter.com/gems/itrigga-cache"
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = "1.8.10"
43
+ s.summary = "Adds caching methods"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<memcached>, [">= 0"])
50
+ s.add_runtime_dependency(%q<itrigga-param_fu>, [">= 0"])
51
+ s.add_runtime_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_runtime_dependency(%q<memcached>, [">= 0"])
54
+ s.add_runtime_dependency(%q<itrigga-param_fu>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<memcached>, [">= 0"])
57
+ s.add_dependency(%q<itrigga-param_fu>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_dependency(%q<memcached>, [">= 0"])
61
+ s.add_dependency(%q<itrigga-param_fu>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<memcached>, [">= 0"])
65
+ s.add_dependency(%q<itrigga-param_fu>, [">= 0"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
68
+ s.add_dependency(%q<memcached>, [">= 0"])
69
+ s.add_dependency(%q<itrigga-param_fu>, [">= 0"])
70
+ end
71
+ end
72
+
@@ -1,4 +1,4 @@
1
- require 'memcached'
1
+
2
2
  require 'trigga/param_fu'
3
3
 
4
4
  module Itrigga
@@ -15,8 +15,11 @@ module Itrigga
15
15
 
16
16
  def self.setup!(opts ={})
17
17
  @default_cache_type = opts[:backend] if opts[:backend]
18
- if opts[:backend] == :memcached
18
+ case opts[:backend]
19
+ when :memcached
19
20
  Itrigga::Cache::Memcache.setup!(opts)
21
+ when :dalli
22
+ Itrigga::Cache::Dalli.setup!(opts)
20
23
  else
21
24
  Itrigga::Cache::Filecache.setup!(opts)
22
25
  end
@@ -26,6 +29,8 @@ module Itrigga
26
29
  case ( opts[:backend] ||= @default_cache_type )
27
30
  when :memcached
28
31
  Itrigga::Cache::Memcache.instance
32
+ when :dalli
33
+ Itrigga::Cache::Dalli.instance
29
34
  when :filecache
30
35
  Itrigga::Cache::Filecache.instance
31
36
  else
@@ -0,0 +1,55 @@
1
+ # http://stackoverflow.com/questions/4217968/a-problem-about-singleton-in-ruby
2
+ #
3
+ # To implement a backend it needs to respond to:
4
+ # - self.setup!
5
+ # - get
6
+ # - set
7
+ # - delete
8
+ #
9
+
10
+ require 'singleton'
11
+
12
+ module Itrigga
13
+ module Cache
14
+
15
+ class Dalli
16
+ include Singleton
17
+
18
+ attr_accessor :cache, :enabled
19
+
20
+ def initialize
21
+ @cache = nil
22
+ end
23
+
24
+ def self.setup!(opts = {})
25
+ servers = opts[:servers] || "localhost:11211"
26
+ opts.delete(:servers)
27
+
28
+ opts[:default_ttl] ||= opts[:timeout] if opts[:timeout] # rename default_ttl to something easier to use
29
+ opts.delete(:timeout)
30
+ instance.enabled = true
31
+
32
+ puts "Dalli client init with: #{servers.inspect} - #{opts.inspect}"
33
+ instance.cache = ::Dalli::Client.new(servers, opts)
34
+ end
35
+
36
+ def get(key, opts = {})
37
+ cache.get key
38
+ end
39
+
40
+ def set(key, value, opts = {})
41
+ if opts[:timeout]
42
+ cache.set key, value, opts[:timeout]
43
+ else
44
+ cache.set key, value
45
+ end
46
+ end
47
+
48
+ def delete(key, opts = {})
49
+ cache.delete key
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Itrigga::Cache::Memcache do
4
+ before do
5
+ Itrigga::Cache::Dalli.reset_instance
6
+ ::Dalli = Module.new unless defined?(::Dalli)
7
+ ::Dalli::Client = Module.new unless defined?(::Dalli::Client)
8
+ ::Dalli::Client.stub!(:new).and_return(@memcached = mock("Memcached"))
9
+ @instance = Itrigga::Cache::Dalli.instance
10
+ end
11
+
12
+ it "should include Singleton" do
13
+ Itrigga::Cache::Dalli.should include Singleton
14
+ end
15
+
16
+ describe "setup!" do
17
+ it "should call Dalli::Client.new with default server" do
18
+ Dalli::Client.should_receive(:new).with("localhost:11211",{})
19
+ Itrigga::Cache::Dalli.setup!
20
+ end
21
+
22
+ it "should call Dalli::Client.new with given server" do
23
+ Dalli::Client.should_receive(:new).with("funky monkeys",{:abc => 123})
24
+ Itrigga::Cache::Dalli.setup!(:servers => "funky monkeys", :abc => 123)
25
+ end
26
+
27
+ it "should call Dalli::Client.new with timeout" do
28
+ Dalli::Client.should_receive(:new).with("funky monkeys",{:default_ttl => 42})
29
+ Itrigga::Cache::Dalli.setup!(:servers => "funky monkeys", :timeout => 42)
30
+ end
31
+
32
+ it "should call Dalli::Client.new with timeout" do
33
+ Dalli::Client.should_receive(:new).with("funky monkeys",{:default_ttl => 42})
34
+ Itrigga::Cache::Dalli.setup!(:servers => "funky monkeys", :default_ttl => 42)
35
+ end
36
+
37
+ it "should assign the memcached instance" do
38
+ Itrigga::Cache::Dalli.setup!(:servers => "funky monkeys", :default_ttl => 42)
39
+ Itrigga::Cache::Dalli.instance.cache.should == @memcached
40
+ end
41
+ end
42
+
43
+
44
+ describe "instance_methods" do
45
+ before do
46
+ @instance.stub!(:cache).and_return(@cache = mock("Memcached"))
47
+ end
48
+
49
+
50
+ describe "get" do
51
+ it "should call cache.get" do
52
+ @cache.should_receive(:get).with("key")
53
+ @instance.get("key")
54
+ end
55
+ end
56
+
57
+ describe "set" do
58
+ it "should call cache.set" do
59
+ @cache.should_receive(:set).with("key","content",42)
60
+ @instance.set("key","content",{:timeout => 42})
61
+ end
62
+ end
63
+
64
+ describe "delete" do
65
+ it "should call cache.delete" do
66
+ @cache.should_receive(:delete).with("key")
67
+ @instance.delete("key")
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -20,6 +20,10 @@ end
20
20
 
21
21
  describe Itrigga::Cache do
22
22
  before do
23
+
24
+ Memcached = Module.new unless defined?(Memcached)
25
+ Memcached::NotFound = Class.new unless defined?(Memcached::NotFound)
26
+
23
27
  Itrigga::Cache.setup!(:backend=>:filecache)
24
28
  @klass = TriggaCacheTestClass.new
25
29
  @klass.stub!(:cache_log) # stub out the logging method in tests
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe Itrigga::Cache::Memcache do
4
4
  before do
5
5
  Itrigga::Cache::Memcache.reset_instance
6
+ ::Memcached = Module.new unless defined?(::Memcached)
6
7
  ::Memcached.stub!(:new).and_return(@memcached = mock("Memcached"))
7
8
  @instance = Itrigga::Cache::Memcache.instance
8
9
  end
@@ -4,12 +4,11 @@ RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
4
 
5
5
  $LOAD_PATH.unshift(File.join(RAILS_ROOT, 'lib'))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'memcached'
8
7
 
9
8
  # Requires supporting files with custom matchers and macros, etc,
10
9
  # in ./support/ and its subdirectories.
11
10
  Dir["#{RAILS_ROOT}/support/**/*.rb"].each {|f| require f }
12
11
 
13
- require 'lib/itrigga/cache'
12
+ require 'itrigga/cache'
14
13
 
15
14
 
metadata CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
4
4
  hash: 19
5
5
  prerelease:
6
6
  segments:
7
+ - 1
8
+ - 1
7
9
  - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Al Davidson
@@ -16,13 +16,9 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-20 00:00:00 +01:00
20
- default_executable:
19
+ date: 2012-03-08 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- prerelease: false
24
- name: memcached
25
- type: :runtime
26
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
27
23
  none: false
28
24
  requirements:
@@ -32,11 +28,11 @@ dependencies:
32
28
  segments:
33
29
  - 0
34
30
  version: "0"
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- prerelease: false
38
31
  name: itrigga-param_fu
32
+ prerelease: false
39
33
  type: :runtime
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
40
36
  version_requirements: &id002 !ruby/object:Gem::Requirement
41
37
  none: false
42
38
  requirements:
@@ -46,12 +42,28 @@ dependencies:
46
42
  segments:
47
43
  - 0
48
44
  version: "0"
45
+ name: itrigga-core_ext
46
+ prerelease: false
47
+ type: :runtime
49
48
  requirement: *id002
50
49
  - !ruby/object:Gem::Dependency
51
- prerelease: false
52
- name: rspec
53
- type: :development
54
50
  version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 23
56
+ segments:
57
+ - 1
58
+ - 0
59
+ - 0
60
+ version: 1.0.0
61
+ name: bundler
62
+ prerelease: false
63
+ type: :runtime
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
55
67
  none: false
56
68
  requirements:
57
69
  - - "="
@@ -62,15 +74,31 @@ dependencies:
62
74
  - 3
63
75
  - 0
64
76
  version: 1.3.0
65
- requirement: *id003
77
+ name: rspec
78
+ prerelease: false
79
+ type: :development
80
+ requirement: *id004
66
81
  - !ruby/object:Gem::Dependency
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - "="
86
+ - !ruby/object:Gem::Version
87
+ hash: 31
88
+ segments:
89
+ - 1
90
+ - 3
91
+ - 2
92
+ version: 1.3.2
93
+ name: rspec-rails
67
94
  prerelease: false
68
- name: bundler
69
95
  type: :development
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ version_requirements: &id006 !ruby/object:Gem::Requirement
71
99
  none: false
72
100
  requirements:
73
- - - ~>
101
+ - - ">="
74
102
  - !ruby/object:Gem::Version
75
103
  hash: 23
76
104
  segments:
@@ -78,12 +106,12 @@ dependencies:
78
106
  - 0
79
107
  - 0
80
108
  version: 1.0.0
81
- requirement: *id004
82
- - !ruby/object:Gem::Dependency
109
+ name: bundler
83
110
  prerelease: false
84
- name: jeweler
85
111
  type: :development
86
- version_requirements: &id005 !ruby/object:Gem::Requirement
112
+ requirement: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ version_requirements: &id007 !ruby/object:Gem::Requirement
87
115
  none: false
88
116
  requirements:
89
117
  - - ~>
@@ -94,12 +122,12 @@ dependencies:
94
122
  - 6
95
123
  - 4
96
124
  version: 1.6.4
97
- requirement: *id005
98
- - !ruby/object:Gem::Dependency
125
+ name: jeweler
99
126
  prerelease: false
100
- name: rcov
101
127
  type: :development
102
- version_requirements: &id006 !ruby/object:Gem::Requirement
128
+ requirement: *id007
129
+ - !ruby/object:Gem::Dependency
130
+ version_requirements: &id008 !ruby/object:Gem::Requirement
103
131
  none: false
104
132
  requirements:
105
133
  - - ">="
@@ -108,12 +136,28 @@ dependencies:
108
136
  segments:
109
137
  - 0
110
138
  version: "0"
111
- requirement: *id006
139
+ name: rcov
140
+ prerelease: false
141
+ type: :development
142
+ requirement: *id008
112
143
  - !ruby/object:Gem::Dependency
144
+ version_requirements: &id009 !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 11
150
+ segments:
151
+ - 1
152
+ - 5
153
+ - 4
154
+ version: 1.5.4
155
+ name: fastercsv
113
156
  prerelease: false
114
- name: memcached
115
- type: :runtime
116
- version_requirements: &id007 !ruby/object:Gem::Requirement
157
+ type: :development
158
+ requirement: *id009
159
+ - !ruby/object:Gem::Dependency
160
+ version_requirements: &id010 !ruby/object:Gem::Requirement
117
161
  none: false
118
162
  requirements:
119
163
  - - ">="
@@ -122,12 +166,12 @@ dependencies:
122
166
  segments:
123
167
  - 0
124
168
  version: "0"
125
- requirement: *id007
126
- - !ruby/object:Gem::Dependency
169
+ name: memcached
127
170
  prerelease: false
128
- name: itrigga-param_fu
129
171
  type: :runtime
130
- version_requirements: &id008 !ruby/object:Gem::Requirement
172
+ requirement: *id010
173
+ - !ruby/object:Gem::Dependency
174
+ version_requirements: &id011 !ruby/object:Gem::Requirement
131
175
  none: false
132
176
  requirements:
133
177
  - - ">="
@@ -136,7 +180,10 @@ dependencies:
136
180
  segments:
137
181
  - 0
138
182
  version: "0"
139
- requirement: *id008
183
+ name: itrigga-param_fu
184
+ prerelease: false
185
+ type: :runtime
186
+ requirement: *id011
140
187
  description: Wraps memcached with helpful methods
141
188
  email: support@itrigga.com
142
189
  executables: []
@@ -149,23 +196,26 @@ extra_rdoc_files:
149
196
  files:
150
197
  - .document
151
198
  - .rspec
199
+ - .rvmrc
152
200
  - Gemfile
153
201
  - Gemfile.lock
154
202
  - LICENSE.txt
155
203
  - README.rdoc
156
204
  - Rakefile
157
205
  - VERSION
206
+ - itrigga-cache.gemspec
158
207
  - lib/itrigga/cache.rb
159
208
  - lib/itrigga/cache/cache.rb
209
+ - lib/itrigga/cache/dalli.rb
160
210
  - lib/itrigga/cache/filecache.rb
161
211
  - lib/itrigga/cache/memcache.rb
212
+ - spec/dalli_spec.rb
162
213
  - spec/filecache_spec.rb
163
214
  - spec/itrigga-cache_spec.rb
164
215
  - spec/memcache_spec.rb
165
216
  - spec/spec.opts
166
217
  - spec/spec_helper.rb
167
218
  - support/singleton_reset.rb
168
- has_rdoc: true
169
219
  homepage: http://gemcutter.com/gems/itrigga-cache
170
220
  licenses:
171
221
  - MIT
@@ -195,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
245
  requirements: []
196
246
 
197
247
  rubyforge_project:
198
- rubygems_version: 1.4.2
248
+ rubygems_version: 1.8.17
199
249
  signing_key:
200
250
  specification_version: 3
201
251
  summary: Adds caching methods