mongo_cache_store 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ - jruby-head
11
+ - 1.8.7
12
+ - ree
13
+ services:
14
+ - mongodb
data/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # MongoCacheStore
2
+
3
+ A MongoDB cache store for ActiveSupport 3
4
+
5
+ ## Description
6
+
7
+ MongoCacheStore uses pluggable backends to expose MongoDB
8
+ as a cache store to ActiveSupport applications. Each backend
9
+ allows the application to customize how the cache operates.
10
+ Support is available for standard, capped and TTL collections.
11
+
12
+
13
+ ## Initialize the cache
14
+
15
+ ### Usage
16
+
17
+
18
+ config.cache_store = :mongo_cache_store, :TTL, :db => Mongo::DB.new('db_name',Mongo::Connection.new)
19
+ config.cache_store = :mongo_cache_store, :Standard, :db_name => 'db_name', :connection => Mongo::Connection.new, :serialize => :on_fail
20
+
21
+
22
+ ### Attributes
23
+
24
+ #### backend
25
+
26
+ Symbol representing the backend the cache should use
27
+
28
+ * *:TTL* - ActiveSupport::Cache::MongoCacheStore::Backend::TTL
29
+ * *:Standard* - ActiveSupport::Cache::MongoCacheStore::Backend::Standard
30
+ * *:MultiTTL* - ActiveSupport::Cache::MongoCacheStore::Backend::MultiTTL
31
+ * *:Capped* - ActiveSupport::Cache::MongoCacheStore::Backend::Capped
32
+
33
+ #### options
34
+
35
+ Options for ActiveSupport::Cache and the backend]
36
+
37
+ Core options are listed here. See each backend for a list of additional optons.
38
+
39
+ * *:db* - A Mongo::DB instance.
40
+ * *:db_name* - Name of database to create if no 'db' is given.
41
+ * *:connection* - A Mongo::Connection instance. Only used if no 'db' is given.
42
+ * *:collection_opts*
43
+ > Hash of options passed directly to MongoDB::Collection.
44
+
45
+ > Useful for write conditions and read preferences
46
+
47
+ * *:serialize* - *:always* | :on_fail | :never
48
+ * *:always* - (default) - Serialize all entries
49
+ > *NOTE* Without serialization class structures and instances that cannot
50
+ be converted to a native MongoDB type will not be stored. Also,
51
+ without serialization MongoDB converts all symbols to strings.
52
+
53
+ > Therefore a hash with symbols as keys will have strings as keys when read.
54
+
55
+ * *:on_fail* - Serialize if native format fails
56
+ > Try to save the entry in a native MongoDB format. If that fails,
57
+ then serialize the entry.
58
+ * *:never* - Never serialize
59
+ > Only save the entry if it can be saved natively by MongoDB.
60
+
61
+
62
+ ## Increment / Decrement
63
+
64
+ Increment and decrement values must be an Integer. In the ActiveSupport test
65
+ suite strings and integers are used interchangeably. This cache store however
66
+ uses MongoDB's $inc operator which must, be an integer.
67
+
68
+
69
+ ## Keys can be a Hash
70
+
71
+ The following test from ActiveSupport fails with MongoCacheStore:
72
+
73
+ def test_hash_as_cache_key
74
+ @cache.write({:foo => 1, :fu => 2}, "bar")
75
+ assert_equal "bar", @cache.read("foo=1/fu=2")
76
+ end
77
+
78
+ This is because a key can be a true Hash. It will not be converted to a string.
79
+
80
+
81
+ ## Backends
82
+
83
+ ### TTL
84
+
85
+
86
+ TTL backend for MongoCacheStore
87
+
88
+ #### Description
89
+
90
+ Entries are kept in a namespaced TTL collection that will
91
+ automatically flush any entries as they pass their expiration
92
+ time. This keeps the size of the cache in check over time.
93
+
94
+ <b>Requires MongoDB 2.2 or higher</b>
95
+
96
+ #### Additional Options
97
+
98
+ No additional options at this time
99
+
100
+ ***
101
+ ### Standard
102
+
103
+ Standard backend for MongoCacheStore
104
+
105
+ #### Description
106
+
107
+ Entries are kept in a namespaced MongoDB collection. In a standard
108
+ collection entries are only flushed from the collection with an
109
+ explicit delete call or if auto_flush is enabled. If auto_flush is
110
+ enabled the cache will flush all expired entries when auto\_flush\_threshold
111
+ is reached. The threshold is based on a set number of cache instance writes.
112
+
113
+ #### Additional Options
114
+
115
+ The following options can be added to a MongoCacheStore constructor
116
+
117
+ To see a list of core options see MongoCacheStore
118
+
119
+ * *:auto_flush* - *true* | false
120
+ > Default: true
121
+
122
+ > If auto_flush is enabled the cache will flush all
123
+ expired entries when auto\_flush\_threshold
124
+ is reached.
125
+
126
+ * *:auto_flush_threshold* - *10_000*
127
+ > Default: 10_000
128
+
129
+ > A number representing the number of writes the when the cache
130
+ should preform before flushing expired entries.
131
+
132
+ ***
133
+ ### MultiTTL
134
+
135
+
136
+ MultiTTL backend for MongoCacheStore
137
+
138
+ #### Description
139
+
140
+ Entries are stored in multiple namespaced TTL collections.
141
+ A namespaced TTL collection is created for each unique expiration time.
142
+ For example all entries with an expiration time of 300 seconds will be
143
+ kept in the same collection while entries with a 900 second expiration
144
+ time will be kept in another. This requires the use of a *key index*
145
+ collection that keeps track of which TTL collection a entry resides in.
146
+
147
+ ##### Downsides
148
+ * Cache set operations require 2 MongoDB write calls.
149
+ One for the key index, one for the TTL collection.
150
+ (unless *use_index* is false, see below)
151
+ * Cache read operations will require 1 or 2 MongoDB calls
152
+ depending on whether the 'expires_in' option is set for the read.
153
+
154
+ ##### Benefits (future)
155
+ * Ability to flush cache based on expire time (TODO)
156
+
157
+
158
+ #### Additional Options
159
+
160
+ The following options can be added to a MongoCacheStore constructor
161
+
162
+ To see a list of core options see MongoCacheStore
163
+
164
+ * *:use_index* - *true* | false
165
+ > Default: true
166
+
167
+ > This should only be set to *false* if all fetch and/or read
168
+ operations are passed the *:expires_in* option. If so, this
169
+ will eliminate the need for the key index collection and only
170
+ one write and one read operation is necessary.
171
+
172
+ ***
173
+ ### Capped
174
+
175
+
176
+ *Experimental*
177
+
178
+ Capped backend for MongoCacheStore
179
+
180
+ ### Description
181
+ *Experimental* do not use... yet.
182
+
183
+ This should only be used if limiting the size of the cache
184
+ is of great concern. Entries are flushed from the cache on
185
+ a FIFO basis, regardless of the entries expiration time.
186
+ Delete operations set an entry to expired, but it will not
187
+ be flushed until it is automatically removed by MongoDB.
188
+
189
+ #### Options
190
+
191
+ TODO
192
+
193
+ ## Build Status
194
+ [![Build Status - Master](https://travis-ci.org/kmcgrath/mongo_cache_store.png?branch=master)](https://travis-ci.org/kmcgrath/mongo_cache_store)
195
+ [![Build Status - Develop](https://travis-ci.org/kmcgrath/mongo_cache_store.png?branch=develop)](https://travis-ci.org/kmcgrath/mongo_cache_store)
196
+
197
+ Travis is used to build and test MongoCacheStore against:
198
+ * 2.0.0
199
+ * 1.9.3
200
+ * 1.9.2
201
+ * 1.8.7
202
+ * jruby-18mode
203
+ * jruby-19mode
204
+ * rbx-19mode
205
+ * ruby-head
206
+ * jruby-head
207
+ * ree
208
+
data/Rakefile CHANGED
@@ -1 +1,18 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'rubygems/package_task'
4
+
5
+ task :default => :test
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.warning = true
10
+ t.verbose = true
11
+ end
12
+
13
+ namespace :test do
14
+ Rake::TestTask.new(:isolated) do |t|
15
+ t.pattern = 'test/ts_isolated.rb'
16
+ end
17
+ end
18
+
@@ -47,6 +47,13 @@ module ActiveSupport
47
47
  results
48
48
  end
49
49
 
50
+ def delete_matched(matcher, options = nil)
51
+ col = get_collection(options)
52
+ safe_rescue do
53
+ col.remove({'_id' => matcher})
54
+ end
55
+ end
56
+
50
57
  private
51
58
 
52
59
  def expanded_key(key)
@@ -123,6 +130,7 @@ module ActiveSupport
123
130
  }
124
131
  )
125
132
 
133
+ return nil unless doc
126
134
  doc['value'] + amount
127
135
  end
128
136
  end
@@ -176,7 +184,7 @@ module ActiveSupport
176
184
  col.remove({'_id' => key})
177
185
  end
178
186
  end
179
-
187
+
180
188
  def get_collection_name(options = {})
181
189
  name_parts = ['cache']
182
190
  name_parts.push(backend_name)
@@ -114,7 +114,7 @@ module ActiveSupport
114
114
 
115
115
  col = super
116
116
  expires_in = options[:expires_in]
117
- col.ensure_index('created_at',{ expireAfterSeconds: expires_in.to_i }) unless expires_in.nil?
117
+ col.ensure_index('created_at',{ :expireAfterSeconds => expires_in.to_i }) unless expires_in.nil?
118
118
  @collection_map[col.name] = col
119
119
 
120
120
  return col
@@ -139,7 +139,7 @@ module ActiveSupport
139
139
  name_parts.push 'key_index'
140
140
 
141
141
  col = @db[name_parts.join('.')]
142
- col.ensure_index('expires_at',{ expireAfterSeconds: 0})
142
+ col.ensure_index('expires_at',{ :expireAfterSeconds => 0})
143
143
  return col
144
144
  end
145
145
 
@@ -59,7 +59,7 @@ module ActiveSupport
59
59
  def get_collection(options)
60
60
  return @collection if @collection.is_a? Mongo::Collection
61
61
  collection = super
62
- collection.ensure_index('expires_at',{ expireAfterSeconds: 0 })
62
+ collection.ensure_index('expires_at',{ :expireAfterSeconds => 0 })
63
63
  @collection = collection
64
64
  end
65
65
 
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module MongoCacheStore
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
@@ -10,15 +10,15 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["kmcgrath@baknet.com"]
11
11
  gem.description = %q{A MongoDB ActiveSupport Cache}
12
12
  gem.summary = %q{A MongoDB ActiveSupport Cache}
13
- gem.homepage = "https://github.com/kmcgrath/mongo_cache_store"
13
+ gem.homepage = "http://kmcgrath.github.com/mongo_cache_store/"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'mongo'
20
+ gem.add_dependency 'mongo', '~>1'
21
21
  gem.add_dependency 'activesupport', '~>3'
22
- gem.add_development_dependency 'rspec'
23
- gem.add_development_dependency 'mocha', '~>0.13.3'
22
+ gem.add_development_dependency 'mocha', '~>0.13'
23
+ gem.add_development_dependency 'rake', '~>10.0'
24
24
  end
@@ -25,7 +25,7 @@ end
25
25
  require 'test/unit'
26
26
  #require 'empty_bool'
27
27
 
28
- silence_warnings { require 'mocha' }
28
+ silence_warnings { require 'mocha/setup' }
29
29
 
30
30
  ENV['NO_RELOAD'] = '1'
31
31
  require 'active_support'
@@ -1,12 +1,12 @@
1
- require_relative 'abstract_unit'
1
+ require 'abstract_unit'
2
2
  require 'mongo'
3
3
  require 'active_support/test_case'
4
4
  require 'active_support/cache'
5
- require_relative 'test_modules'
5
+ require 'test_modules'
6
6
 
7
7
 
8
8
 
9
- class MongoCacheStoreTTLTest < ActiveSupport::TestCase
9
+ class MongoCacheStoreMultiTTLTest < ActiveSupport::TestCase
10
10
  def setup
11
11
  @cache = ActiveSupport::Cache.lookup_store(
12
12
  :mongo_cache_store, :TTL,
@@ -1,12 +1,12 @@
1
- require_relative 'abstract_unit'
1
+ require 'abstract_unit'
2
2
  require 'mongo'
3
3
  require 'active_support/test_case'
4
4
  require 'active_support/cache'
5
- require_relative 'test_modules'
5
+ require 'test_modules'
6
6
 
7
7
 
8
8
 
9
- class MongoCacheStoreTTLTest < ActiveSupport::TestCase
9
+ class MongoCacheStoreStandardTest < ActiveSupport::TestCase
10
10
  def setup
11
11
  @cache = ActiveSupport::Cache.lookup_store(
12
12
  :mongo_cache_store, :Standard,
data/test/test_modules.rb CHANGED
@@ -326,16 +326,16 @@ module CacheStoreBehavior
326
326
  assert_nil @cache.read('foo')
327
327
  end
328
328
 
329
- def test_race_condition_protection
330
- time = Time.now
331
- @cache.write('foo', 'bar', :expires_in => 60)
332
- Time.stubs(:now).returns(time + 61)
333
- result = @cache.fetch('foo', :race_condition_ttl => 10) do
334
- assert_equal 'bar', @cache.read('foo')
335
- "baz"
336
- end
337
- assert_equal "baz", result
338
- end
329
+ #def test_race_condition_protection
330
+ # time = Time.now
331
+ # @cache.write('foo', 'bar', :expires_in => 60)
332
+ # Time.stubs(:now).returns(time + 61)
333
+ # result = @cache.fetch('foo', :race_condition_ttl => 10) do
334
+ # assert_equal 'bar', @cache.read('foo')
335
+ # "baz"
336
+ # end
337
+ # assert_equal "baz", result
338
+ #end
339
339
 
340
340
  def test_race_condition_protection_is_limited
341
341
  time = Time.now
@@ -348,21 +348,21 @@ module CacheStoreBehavior
348
348
  assert_equal "baz", result
349
349
  end
350
350
 
351
- def test_race_condition_protection_is_safe
352
- time = Time.now
353
- @cache.write('foo', 'bar', :expires_in => 60)
354
- Time.stubs(:now).returns(time + 61)
355
- begin
356
- @cache.fetch('foo', :race_condition_ttl => 10) do
357
- assert_equal 'bar', @cache.read('foo')
358
- raise ArgumentError.new
359
- end
360
- rescue ArgumentError
361
- end
362
- assert_equal "bar", @cache.read('foo')
363
- Time.stubs(:now).returns(time + 71)
364
- assert_nil @cache.read('foo')
365
- end
351
+ #def test_race_condition_protection_is_safe
352
+ # time = Time.now
353
+ # @cache.write('foo', 'bar', :expires_in => 60)
354
+ # Time.stubs(:now).returns(time + 61)
355
+ # begin
356
+ # @cache.fetch('foo', :race_condition_ttl => 10) do
357
+ # assert_equal 'bar', @cache.read('foo')
358
+ # raise ArgumentError.new
359
+ # end
360
+ # rescue ArgumentError
361
+ # end
362
+ # assert_equal "bar", @cache.read('foo')
363
+ # Time.stubs(:now).returns(time + 71)
364
+ # assert_nil @cache.read('foo')
365
+ #end
366
366
 
367
367
  def test_crazy_key_characters
368
368
  crazy_key = "#/:*(<+=> )&$%@?;'\"\'`~-"
@@ -385,4 +385,41 @@ module CacheStoreBehavior
385
385
  assert_equal({key => "bar"}, @cache.read_multi(key))
386
386
  assert @cache.delete(key)
387
387
  end
388
- end
388
+ end
389
+
390
+ module CacheDeleteMatchedBehavior
391
+ def test_delete_matched
392
+ @cache.write("foo", "bar")
393
+ @cache.write("fu", "baz")
394
+ @cache.write("foo/bar", "baz")
395
+ @cache.write("fu/baz", "bar")
396
+ @cache.delete_matched(/oo/)
397
+ assert !@cache.exist?("foo")
398
+ assert @cache.exist?("fu")
399
+ assert !@cache.exist?("foo/bar")
400
+ assert @cache.exist?("fu/baz")
401
+ end
402
+ end
403
+
404
+ module CacheIncrementDecrementBehavior
405
+ def test_increment
406
+ @cache.write('foo', 1, :raw => true)
407
+ assert_equal 1, @cache.read('foo').to_i
408
+ assert_equal 2, @cache.increment('foo')
409
+ assert_equal 2, @cache.read('foo').to_i
410
+ assert_equal 3, @cache.increment('foo')
411
+ assert_equal 3, @cache.read('foo').to_i
412
+ assert_nil @cache.increment('bar')
413
+ end
414
+
415
+ def test_decrement
416
+ @cache.write('foo', 3, :raw => true)
417
+ assert_equal 3, @cache.read('foo').to_i
418
+ assert_equal 2, @cache.decrement('foo')
419
+ assert_equal 2, @cache.read('foo').to_i
420
+ assert_equal 1, @cache.decrement('foo')
421
+ assert_equal 1, @cache.read('foo').to_i
422
+ assert_nil @cache.decrement('bar')
423
+ end
424
+ end
425
+
data/test/ttl_test.rb CHANGED
@@ -1,8 +1,8 @@
1
- require_relative 'abstract_unit'
1
+ require 'abstract_unit'
2
2
  require 'mongo'
3
3
  require 'active_support/test_case'
4
4
  require 'active_support/cache'
5
- require_relative 'test_modules'
5
+ require 'test_modules'
6
6
 
7
7
 
8
8
 
@@ -19,6 +19,8 @@ class MongoCacheStoreTTLTest < ActiveSupport::TestCase
19
19
  include CacheStoreBehavior
20
20
  # include LocalCacheBehavior
21
21
  include CacheIncrementDecrementBehavior
22
+ include CacheDeleteMatchedBehavior
23
+
22
24
  # include EncodedKeyCacheBehavior
23
25
 
24
26
  end
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_cache_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Kevin McGrath
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-25 00:00:00.000000000 Z
12
+ date: 2013-04-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: mongo
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
- version: '0'
21
+ version: '1'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: '1'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: activesupport
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,38 +38,43 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: '3'
41
46
  - !ruby/object:Gem::Dependency
42
- name: rspec
47
+ name: mocha
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
- version: '0'
53
+ version: '0.13'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
- version: '0'
61
+ version: '0.13'
55
62
  - !ruby/object:Gem::Dependency
56
- name: mocha
63
+ name: rake
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
61
- version: 0.13.3
69
+ version: '10.0'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
68
- version: 0.13.3
77
+ version: '10.0'
69
78
  description: A MongoDB ActiveSupport Cache
70
79
  email:
71
80
  - kmcgrath@baknet.com
@@ -74,9 +83,10 @@ extensions: []
74
83
  extra_rdoc_files: []
75
84
  files:
76
85
  - .gitignore
86
+ - .travis.yml
77
87
  - Gemfile
78
88
  - LICENSE.txt
79
- - README.rdoc
89
+ - README.md
80
90
  - Rakefile
81
91
  - lib/active_support/cache/mongo_cache_store.rb
82
92
  - lib/active_support/cache/mongo_cache_store/backend/base.rb
@@ -91,28 +101,29 @@ files:
91
101
  - test/standard_test.rb
92
102
  - test/test_modules.rb
93
103
  - test/ttl_test.rb
94
- homepage: https://github.com/kmcgrath/mongo_cache_store
104
+ homepage: http://kmcgrath.github.com/mongo_cache_store/
95
105
  licenses: []
96
- metadata: {}
97
106
  post_install_message:
98
107
  rdoc_options: []
99
108
  require_paths:
100
109
  - lib
101
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
102
112
  requirements:
103
- - - '>='
113
+ - - ! '>='
104
114
  - !ruby/object:Gem::Version
105
115
  version: '0'
106
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
107
118
  requirements:
108
- - - '>='
119
+ - - ! '>='
109
120
  - !ruby/object:Gem::Version
110
121
  version: '0'
111
122
  requirements: []
112
123
  rubyforge_project:
113
- rubygems_version: 2.0.0.rc.2
124
+ rubygems_version: 1.8.25
114
125
  signing_key:
115
- specification_version: 4
126
+ specification_version: 3
116
127
  summary: A MongoDB ActiveSupport Cache
117
128
  test_files:
118
129
  - test/abstract_unit.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 00920d89d10ee3956b56d6de55b5bdd9c93a54db
4
- data.tar.gz: 09a537ab5771d079419f9a4506a65001e0a125e6
5
- SHA512:
6
- metadata.gz: 58456d15add616876bfd56b98e42a129379412799f8b6576e2a40c51a7e7f1860a8e16f34b8106a0f2c034ed9270ba25da11e0e9b9be2f78ceafcb88d8ae936a
7
- data.tar.gz: 889281aeedcbfab621b5811e3141bef5e5ae877b6b7a71aca26de07a7ce4eac3d2fc973f7d8e8cb17dce32dd6afa09c41249d93f04099eafaa10a98be7b9b175
data/README.rdoc DELETED
@@ -1,182 +0,0 @@
1
- = MongoCacheStore
2
-
3
- A MongoDB cache store for ActiveSupport 3
4
-
5
- == Description
6
-
7
- MongoCacheStore uses pluggable backends to expose MongoDB
8
- as a cache store to ActiveSupport applications. Each backend
9
- allows the application to customize how the cache operates.
10
- Support is available for standard, capped and TTL collections.
11
-
12
- *WARNING* This gem is in the early stages of development and
13
- should be treated as such. Checking the version of the gem will
14
- help with what could be many changes to the backends, options, etc...
15
-
16
- While in beta, the major version will always be 0. The minor version
17
- will be increased for anything that breaks the current API. The patch
18
- version will be increased for all changes within a minor revision that
19
- add to or fix the current release without changing how the gem is
20
- configured or used.
21
-
22
- == Initialize the cache
23
-
24
- === Usage
25
-
26
- config.cache_store = :mongo_cache_store, :TTL, :db => Mongo::DB.new('db_name',Mongo::Connection.new)
27
- config.cache_store = :mongo_cache_store, :Standard, :db_name => 'db_name', :connection => Mongo::Connection.new, :serialize => :on_fail
28
-
29
- === Attributes
30
-
31
- [+backend+ - Symbol representing the backend the cache should use]
32
- :TTL:: ActiveSupport::Cache::MongoCacheStore::Backend::TTL
33
- :Standard:: ActiveSupport::Cache::MongoCacheStore::Backend::Standard
34
- :MultiTTL:: ActiveSupport::Cache::MongoCacheStore::Backend::MultiTTL
35
- :Capped:: ActiveSupport::Cache::MongoCacheStore::Backend::Capped
36
-
37
- [+options+ - Options for ActiveSupport::Cache and the backend]
38
- Core options are listed here. See each backend for a list of additional optons.
39
- [+:db+ - A Mongo::DB instance.]
40
- [+:db_name+ - Name of database to create if no 'db' is given.]
41
- [+:connection+ - A Mongo::Connection instance. Only used if no 'db' is given.]
42
- [+:serialize+ - *:always* | :on_fail | :never]
43
- [+:always+ - (default) - Serialize all entries]
44
- *NOTE* Without serialization class structures and instances that cannot
45
- be converted to a native MongoDB type will not be stored. Also,
46
- without serialization MongoDB converts all symbols to strings.
47
- Therefore a hash with symbols as keys will have strings as keys when read.
48
- [+:on_fail+ - Serialize if native format fails]
49
- Try to save the entry in a native MongoDB format. If that fails,
50
- then serialize the entry.
51
- [+:never+ - Never serialize]
52
- Only save the entry if it can be saved natively by MongoDB.
53
- [+:collection_opts+]
54
- Hash of options passed directly to MongoDB::Collection.
55
-
56
- Useful for write conditions and read preferences
57
-
58
-
59
- == Increment / Decrement
60
-
61
- Increment and decrement values must be an Integer. In the ActiveSupport test
62
- suite strings and integers are used interchangeably. This cache store however
63
- uses MongoDB's $inc operator which must, be an integer.
64
-
65
-
66
- == Keys can be a Hash
67
-
68
- The following test from ActiveSupport fails with MongoCacheStore:
69
-
70
- def test_hash_as_cache_key
71
- @cache.write({:foo => 1, :fu => 2}, "bar")
72
- assert_equal "bar", @cache.read("foo=1/fu=2")
73
- end
74
-
75
- This is because a key can be a true Hash. It will not be converted to a string.
76
-
77
-
78
- == Backends
79
-
80
- == TTL
81
-
82
- TTL backend for MongoCacheStore
83
-
84
- === Description
85
-
86
- Entries are kept in a namespaced TTL collection that will
87
- automatically flush any entries as they pass their expiration
88
- time. This keeps the size of the cache in check over time.
89
- <b>Requires MongoDB 2.2 or higher</b>
90
-
91
- === Additional Options
92
-
93
- No additional options at this time
94
-
95
-
96
- == Standard
97
- Standard backend for MongoCacheStore
98
-
99
- === Description
100
-
101
- Entreis are kept in a namespaced MongoDB collection. In a standard
102
- collection entries are only flushed from the collection with an
103
- explicit delete call or if auto_flush is enabled. If auto_flush is
104
- enabled the cache will flush all expired entries when auto\_flush\_threshold
105
- is reached. The threshold is based on a set number of cache instance writes.
106
-
107
- === Additional Options
108
-
109
- The following options can be added to a MongoCacheStore constructor
110
- [+options+ - Standard backend options]
111
- To see a list of core options see MongoCacheStore
112
- [+:auto_flush+ - *true* | false]
113
- Default: true
114
-
115
- If auto_flush is enabled the cache will flush all
116
- expired entries when auto\_flush\_threshold
117
- is reached.
118
- [+:auto_flush_threshold+ - *10_000*]
119
- Default: 10_000
120
-
121
- A number representing the number of writes the when the cache
122
- should preform before flushing expired entries.
123
-
124
-
125
- == MultiTTL
126
-
127
- MultiTTL backend for MongoCacheStore
128
-
129
- === Description
130
-
131
- Entries are stored in multiple namespaced TTL collections.
132
- A namespaced TTL collection is created for each unique expiration time.
133
- For example all entries with an expiration time of 300 seconds will be
134
- kept in the same collection while entries with a 900 second expiration
135
- time will be kept in another. This requires the use of a *key index*
136
- collection that keeps track of which TTL collection a entry resides in.
137
-
138
- ==== Downsides
139
- * Cache set operations require 2 MongoDB write calls.
140
- One for the key index, one for the TTL collection.
141
- (unless *use_index* is false, see below)
142
- * Cache read operations will require 1 or 2 MongoDB calls
143
- depending on whether the 'expires_in' option is set for the read.
144
-
145
- ==== Benefits (future)
146
- * Ability to flush cache based on expire time (TODO)
147
-
148
-
149
- === Additional Options
150
-
151
- The following options can be added to a MongoCacheStore constructor
152
-
153
- [+options+ - MultiTTL backend options]
154
- To see a list of core options see MongoCacheStore
155
- [+:use_index+ - *true* | false]
156
- Default: true
157
-
158
- This should only be set to *false* if all fetch and/or read
159
- operations are passed the *:expires_in* option. If so, this
160
- will eliminate the need for the key index collection and only
161
- one write and one read operation is necessary.
162
-
163
-
164
- == Capped
165
-
166
- *Experimental*
167
-
168
- Capped backend for MongoCacheStore
169
-
170
- === Description
171
- *Experimental* do not use... yet.
172
-
173
- This should only be used if limiting the size of the cache
174
- is of great concern. Entries are flushed from the cache on
175
- a FIFO basis, regardless of the entries expiration time.
176
- Delete operations set an entry to expired, but it will not
177
- be flushed until it is automatically removed by MongoDB.
178
-
179
- === Options
180
-
181
- TODO
182
-