garner 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +35 -0
  5. data/.travis.yml +13 -0
  6. data/CHANGELOG.md +130 -0
  7. data/CONTRIBUTING.md +118 -0
  8. data/Gemfile +3 -0
  9. data/README.md +1 -0
  10. data/Rakefile +39 -0
  11. data/UPGRADING.md +118 -0
  12. data/garner.gemspec +44 -0
  13. data/lib/garner.rb +21 -21
  14. data/lib/garner/cache.rb +13 -6
  15. data/lib/garner/cache/binding.rb +6 -14
  16. data/lib/garner/cache/context.rb +11 -12
  17. data/lib/garner/cache/identity.rb +1 -1
  18. data/lib/garner/config.rb +12 -7
  19. data/lib/garner/mixins/active_record.rb +3 -3
  20. data/lib/garner/mixins/active_record/base.rb +2 -2
  21. data/lib/garner/mixins/mongoid.rb +4 -4
  22. data/lib/garner/mixins/mongoid/document.rb +8 -12
  23. data/lib/garner/mixins/mongoid/identity.rb +5 -6
  24. data/lib/garner/mixins/rack.rb +1 -2
  25. data/lib/garner/strategies/binding/invalidation/base.rb +2 -4
  26. data/lib/garner/strategies/binding/invalidation/binding_index.rb +1 -3
  27. data/lib/garner/strategies/binding/invalidation/touch.rb +0 -2
  28. data/lib/garner/strategies/binding/key/base.rb +1 -3
  29. data/lib/garner/strategies/binding/key/binding_index.rb +3 -4
  30. data/lib/garner/strategies/binding/key/cache_key.rb +0 -2
  31. data/lib/garner/strategies/binding/key/safe_cache_key.rb +2 -3
  32. data/lib/garner/strategies/context/key/base.rb +1 -3
  33. data/lib/garner/strategies/context/key/caller.rb +9 -12
  34. data/lib/garner/strategies/context/key/jsonp.rb +3 -6
  35. data/lib/garner/strategies/context/key/request_get.rb +2 -4
  36. data/lib/garner/strategies/context/key/request_path.rb +1 -3
  37. data/lib/garner/strategies/context/key/request_post.rb +2 -4
  38. data/lib/garner/version.rb +1 -1
  39. data/spec/garner/cache/context_spec.rb +38 -0
  40. data/spec/garner/cache/identity_spec.rb +68 -0
  41. data/spec/garner/cache_spec.rb +49 -0
  42. data/spec/garner/config_spec.rb +17 -0
  43. data/spec/garner/mixins/mongoid/document_spec.rb +80 -0
  44. data/spec/garner/mixins/mongoid/identity_spec.rb +140 -0
  45. data/spec/garner/mixins/rack_spec.rb +48 -0
  46. data/spec/garner/strategies/binding/invalidation/binding_index_spec.rb +14 -0
  47. data/spec/garner/strategies/binding/invalidation/touch_spec.rb +23 -0
  48. data/spec/garner/strategies/binding/key/binding_index_spec.rb +245 -0
  49. data/spec/garner/strategies/binding/key/cache_key_spec.rb +29 -0
  50. data/spec/garner/strategies/binding/key/safe_cache_key_spec.rb +61 -0
  51. data/spec/garner/strategies/context/key/caller_spec.rb +106 -0
  52. data/spec/garner/strategies/context/key/jsonp_spec.rb +22 -0
  53. data/spec/garner/strategies/context/key/request_get_spec.rb +33 -0
  54. data/spec/garner/strategies/context/key/request_path_spec.rb +28 -0
  55. data/spec/garner/strategies/context/key/request_post_spec.rb +34 -0
  56. data/spec/garner/version_spec.rb +11 -0
  57. data/spec/integration/active_record_spec.rb +43 -0
  58. data/spec/integration/grape_spec.rb +33 -0
  59. data/spec/integration/mongoid_spec.rb +355 -0
  60. data/spec/integration/rack_spec.rb +77 -0
  61. data/spec/integration/sinatra_spec.rb +29 -0
  62. data/spec/performance/strategy_benchmark.rb +59 -0
  63. data/spec/performance/support/benchmark_context.rb +31 -0
  64. data/spec/performance/support/benchmark_context_wrapper.rb +67 -0
  65. data/spec/shared/binding_invalidation_strategy.rb +17 -0
  66. data/spec/shared/binding_key_strategy.rb +35 -0
  67. data/spec/shared/conditional_get.rb +48 -0
  68. data/spec/shared/context_key_strategy.rb +24 -0
  69. data/spec/spec_helper.rb +24 -0
  70. data/spec/spec_support.rb +5 -0
  71. data/spec/support/active_record.rb +36 -0
  72. data/spec/support/cache.rb +15 -0
  73. data/spec/support/garner.rb +5 -0
  74. data/spec/support/mongoid.rb +71 -0
  75. metadata +155 -157
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a593ed7c69343123cf6aa7152da17d9403455cc
4
+ data.tar.gz: 2c93f44ef0551b09a947a54dd1dcdaac8145dac4
5
+ SHA512:
6
+ metadata.gz: f1448f9b7506742c5ceaae135f9e193080e76350366ed9e62cde64c7dd47f0dd7064a934dad934e6ae722823f64c5044da92899d6934c57924e29b9836ce3d21
7
+ data.tar.gz: 61ffea9d8c44c86e5fae7f5db352c0fa83880e6e8d317533e81953d5c36ded5beec5802d5846916fbcbc1f9f243898646e4c0f32aad163a002671a9f53eba837
@@ -0,0 +1,7 @@
1
+ Gemfile.lock
2
+ .yardoc
3
+ coverage
4
+ doc
5
+ pkg
6
+ log
7
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+
@@ -0,0 +1,35 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
4
+
5
+ LineLength:
6
+ Enabled: false
7
+
8
+ MethodLength:
9
+ Enabled: false
10
+
11
+ ClassLength:
12
+ Enabled: false
13
+
14
+ CyclomaticComplexity:
15
+ Enabled: false
16
+
17
+ Documentation:
18
+ # don't require classes to be documented
19
+ Enabled: false
20
+
21
+ Encoding:
22
+ # no need to always specify encoding
23
+ Enabled: false
24
+
25
+ DoubleNegation:
26
+ Enabled: false
27
+
28
+ RaiseArgs:
29
+ Enabled: false
30
+
31
+ RescueModifier:
32
+ Enabled: false
33
+
34
+ ModuleFunction:
35
+ Enabled: false
@@ -0,0 +1,13 @@
1
+ services:
2
+ - mongodb
3
+ - memcache
4
+
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.1.2
8
+ - rbx-2
9
+ - jruby-19mode
10
+
11
+ env:
12
+ - MONGOID_VERSION=3
13
+ - MONGOID_VERSION=4
@@ -0,0 +1,130 @@
1
+ 0.5.0 (7/17/2014)
2
+ -----------------
3
+
4
+ * [#70](https://github.com/artsy/garner/pull/70): Added a `whiny_nils` configuration variable (default: `true`) which determines whether Garner raises exceptions on `nil` bindings - [@fancyremarker](https://github.com/fancyremarker).
5
+ * [#72](https://github.com/artsy/garner/issues/72): Fix: ActiveRecord 4 support, `cache_key` is now in `:nsec` format - [@dblock](https://github.com/dblock).
6
+ * [#74](https://github.com/artsy/garner/pull/74): Removed Jeweler, rewritten .gemspec - [@dblock](https://github.com/dblock).
7
+ * [#76](https://github.com/artsy/garner/pull/76): Added Rubocop, Ruby-style linter - [@dblock](https://github.com/dblock).
8
+ * [#77](https://github.com/artsy/garner/pull/77): Running tests on Ruby 2.0, 2.1.2, Rubinius and JRuby - [@dblock](https://github.com/dblock).
9
+
10
+ 0.4.5 (10/15/2013)
11
+ ------------------
12
+
13
+ * Fixed [#62](https://github.com/artsy/garner/issues/62): fix garnered_find in `Garner::Mixins::Mongoid::Document.garnered_find` to support finding multiple objects, matching Mongoid's find - [@mzikherman](https://github.com/mzikherman).
14
+ * Fixed [#60](https://github.com/artsy/garner/issues/60): don't return cache keys for Mongoid::Document#identify(nil) - [@fancyremarker](https://github.com/fancyremarker).
15
+
16
+ 0.4.4 (7/11/2013)
17
+ -----------------
18
+
19
+ * Fixed [#47](https://github.com/artsy/garner/issues/47): use a database index when generating proxy binding in `Garner::Mixins::Mongoid::Identity` with multiple `Garner.config.mongoid_identity_fields` - [@dblock](https://github.com/dblock).
20
+
21
+ 0.4.3 (7/5/2013)
22
+ ----------------
23
+
24
+ * Stored `ruby_context` from which a `Garner::Cache::Identity` was initialized as an `attr_accessor` on the object - [@fancyremarker](https://github.com/fancyremarker).
25
+ * Fixed `cache_enabled?` logic and added a `nocache` declaration to `Garner::Cache::Identity` - [@fancyremarker](https://github.com/fancyremarker).
26
+ * Fixed #44, in which the BindingIndex was mistakenly storing values to cache for bindings with a nil canonical binding - [@fancyremarker](https://github.com/fancyremarker).
27
+ * Added `Garner.config.invalidate_mongoid_root` option, to always invalidate the root document when an embedded document is invalidated - [@fancyremarker](https://github.com/fancyremarker).
28
+
29
+ 0.4.2 (6/28/2013)
30
+ -----------------
31
+
32
+ * Fixed `Caller` strategy when using Rails - [@fancyremarker](https://github.com/fancyremarker).
33
+
34
+ 0.4.1 (6/28/2013)
35
+ -----------------
36
+
37
+ * Added a `rake benchmark` task to compare different binding key/invalidation strategy pairs - [@fancyremarker](https://github.com/fancyremarker).
38
+ * Improved the performance of the `SafeCacheKey` strategy on virtual `Garner::Mixins::Mongoid::Identity` bindings by properly memoizing the corresponding document - [@fancyremarker](https://github.com/fancyremarker).
39
+ * Improved the performance of the `SafeCacheKey` strategy on class bindings by making 1 database call per key application, instead of 3 - [@fancyremarker](https://github.com/fancyremarker).
40
+ * Removed the `Garner.config.mongoid_binding_key_strategy` and `Garner.config.mongoid_invalidation_key_strategy`. Garner now uses just one default key/invalidation strategy pair for all binding types - [@fancyremarker](https://github.com/fancyremarker).
41
+ * Added an ActiveRecord mixin, `Garner::Mixins::ActiveRecord::Base`, per #35 - [@fancyremarker](https://github.com/fancyremarker).
42
+ * Eliminated the need to `require "garner/mixins/rack"` before declaring `Garner.config.rack_context_key_strategies`, per #35 - [@fancyremarker](https://github.com/fancyremarker).
43
+ * Fixed a bug in binding to classes via the `SafeCacheKey` and `Touch` strategy pair, where class-bound results would not be invalidated when an instance of the class was destroyed - [@fancyremarker](https://github.com/fancyremarker).
44
+ * Added `BindingIndex` binding key/invalidation strategy pair, which uses a two-level lookup for computing cache keys - [@fancyremarker](https://github.com/fancyremarker).
45
+
46
+ 0.4.0 (6/14/2013)
47
+ -----------------
48
+
49
+ * Complete rewrite of Garner. See [UPGRADING](UPGRADING.md) for details on how to upgrade from Garner 0.3.3 and earlier versions - [@fancyremarker](https://github.com/fancyremarker).
50
+ * Fixed #6: Garner fails if Mongoid not loaded yet - [@fancyremarker](https://github.com/fancyremarker).
51
+ * Closed #12: Support arrays in `Garner.config.mongoid_identity_fields`- [@fancyremarker](https://github.com/fancyremarker).
52
+ * Closed #13: Replace faulty multiple-identity logic- [@fancyremarker](https://github.com/fancyremarker).
53
+ * Fixed #14: Disambiguate binding models by `:id` and `:slug`- [@fancyremarker](https://github.com/fancyremarker).
54
+ * Fixed #15: Remove need for `cache_as` from subclassed Mongoid models - [@fancyremarker](https://github.com/fancyremarker).
55
+ * Closed #23: Abstract all Grape mixins to be more generically Rack mixins - [@fancyremarker](https://github.com/fancyremarker).
56
+ * Closed #24: Implement `garnered_find` method for `Mongoid::Document` classes - [@fancyremarker](https://github.com/fancyremarker).
57
+ * Extracted `Binding`, `Context` and `Identity` as explicit classes from `ObjectIdentity` - [@fancyremarker](https://github.com/fancyremarker).
58
+ * Added support for all ActiveModel-compliant ORMs - [@fancyremarker](https://github.com/fancyremarker).
59
+ * Removed HTTP caching responsibilities from the library entirely - [@fancyremarker](https://github.com/fancyremarker).
60
+ * Introduced a `SafeCacheKey` binding key strategy, which appends subsecond precision to cache keys, to make them usable - [@fancyremarker](https://github.com/fancyremarker).
61
+ * Added a `cache_key` implementation at the class level in Mongoid, which returns the `cache_key` of the most recently updated document in the collection (by `:updated_at`) - [@fancyremarker](https://github.com/fancyremarker).
62
+ * Fixed #29: Restrict the filename string used for the `Caller` context key strategy to just the portion of the path relevant to the current app. In a Rails app, this defaults to Rails.root; otherwise we search for the nearest ancestor directory containing a Gemfile - [@fancyremarker](https://github.com/fancyremarker).
63
+
64
+ 0.3.3 (6/10/2013)
65
+ -----------------
66
+
67
+ * Fix: parent documents are properly invalidated on creation of an embedded document - [@fancyremarker](https://github.com/fancyremarker).
68
+
69
+ 0.3.2 (5/16/2013)
70
+ -----------------
71
+
72
+ * Fix: calling `invalidate` on an embedded document in an `embeds_many` relationship - [@fancyremarker](https://github.com/fancyremarker).
73
+ * `Garner::Strategies::Keys::Caller` no longer depends on ActiveSupport - [@oripekelman](https://github.com/oripekelman), [@dblock](https://github.com/dblock).
74
+ * Added `Garner::Strategies::Keys::RequestPost` for POST parameters - [@oripekelman](https://github.com/oripekelman).
75
+
76
+ 0.3.1
77
+ -----
78
+
79
+ * Do not attempt to fetch again objects in `Garner::Cache::ObjectIdentity.cache_multi` after they were not retrieved from `read_multi`, write them directly to cache - [@dblock](https://github.com/dblock).
80
+
81
+ 0.3
82
+ ---
83
+
84
+ * Added `Garner::Cache::ObjectIdentity.cache_multi` that can now take an array of bindings to return an array of objects - [@dblock](https://github.com/dblock).
85
+ * When fetching an array of objects via `Garner::Cache::ObjectIdentity.cache_multi`, Garner will use `read_multi` if provided by the cache store - [@dblock](https://github.com/dblock).
86
+
87
+ 0.2.1
88
+ -----
89
+
90
+ * Faster invalidation on Mongoid model creation, only invalidate class - [@dblock](https://github.com/dblock).
91
+ * Invalidate cache after a Mongoid model has been updated or destroyed, not before - [@dblock](https://github.com/dblock).
92
+
93
+ 0.2
94
+ ---
95
+
96
+ * The `Keys::Caller` strategy now allows specifying the caller explicitly by passing a `:caller` as part of the context - [@fancyremarker](https://github.com/fancyremarker).
97
+ * Fix: `invalidate` no longer writes a new index key for each object binding; instead it only deletes existing index keys - [@fancyremarker](https://github.com/fancyremarker).
98
+ * Fix: Invoking Garner helper methods from within an IRB session no longer crashes inside the `Keys::Caller` strategy - [@fancyremarker](https://github.com/fancyremarker).
99
+
100
+ 0.1.3
101
+ -----
102
+
103
+ * Split `Garner::Objects::ETag` into a configurable `Garner::Strategies::ETags` module, making `Garner::Strategies::ETags::GrapeETag` the new default, for better integration with Grape - [@fancyremarker](https://github.com/fancyremarker).
104
+ * Added `Garner::Strategies::Keys::Key`, that inserts the value of `:key` within the requested context, useful to explicitly declare an element of a cache key - [@dblock](https://github.com/dblock).
105
+ * Fix: `Garner::Strategies::Keys::Caller` excludes lines with `lib/garner`, workaround for Heroku - [@dblock](https://github.com/dblock).
106
+ * Only load Grape and Mongoid mixins when necessary - [@billgloff](https://github.com/billgloff).
107
+ * Fix: Grape API version is properly passed through to key context when using `Garner::Strategies::Keys::Version` - [@fancyremarker](https://github.com/fancyremarker).
108
+ * Added support for caching responses to JSONP requests, via `Garner::Strategies::Keys::Jsonp` - [@fancyremarker](https://github.com/fancyremarker).
109
+
110
+ 0.1.2
111
+ -----
112
+
113
+ * Fix: `Garner::Mixins::Grape::Cache` improperly handles `nil` cache hits or `cache_enabled?` returning `false` in `cache_or_304` - [@dblock](https://github.com/dblock).
114
+
115
+ 0.1.1
116
+ -----
117
+
118
+ * Initial public release at [GoRuCo](http://goruco.com), read the [announcement](http://artsy.github.com/blog/2012/05/30/restful-api-caching-with-garner/).
119
+ * Grape mixin takes a single parameter, binding and context are extracted from it - [@dblock](https://github.com/dblock).
120
+
121
+ 0.1
122
+ ---
123
+
124
+ * Initial implementation based on [@fancyremarker](https://github.com/fancyremarker)'s original code.
125
+ * Rack middleware for cache busting, `Garner::Middleware::Cache::Bust` - [@dblock](https://github.com/dblock).
126
+ * Generating ETags, `Garner::Objects::ETag` - [@dblock](https://github.com/dblock).
127
+ * `Garner::Cache::ObjectIdentity` cache - [@dblock](https://github.com/dblock).
128
+ * `Version`, `Caller`, `RequestPath` and `RequestGet` key generation strategies - [@dblock](https://github.com/dblock).
129
+ * `Expiration` cache strategy - [@dblock](https://github.com/dblock).
130
+ * [Grape](https://github.com/intridea/grape) and [Mongoid](https://github.com/mongoid/mongoid/) mixins - [@dblock](https://github.com/dblock).
@@ -0,0 +1,118 @@
1
+ Contributing to Garner
2
+ ======================
3
+
4
+ Garner is work of [many of contributors](https://github.com/artsy/garner/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/artsy/garner/pulls), [propose features and discuss issues](https://github.com/artsy/garner/issues).
5
+
6
+ #### Fork the Project
7
+
8
+ Fork the [project on Github](https://github.com/artsy/garner) and check out your copy.
9
+
10
+ ```
11
+ git clone https://github.com/contributor/garner.git
12
+ cd garner
13
+ git remote add upstream https://github.com/artsy/garner.git
14
+ ```
15
+
16
+ #### Create a Topic Branch
17
+
18
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
19
+
20
+ ```
21
+ git checkout master
22
+ git pull upstream master
23
+ git checkout -b my-feature-branch
24
+ ```
25
+
26
+ #### Bundle Install and Test
27
+
28
+ Ensure that you can build the project and run tests.
29
+
30
+ ```
31
+ bundle install
32
+ bundle exec rake
33
+ ```
34
+
35
+ #### Write Tests
36
+
37
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec](spec).
38
+
39
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
40
+
41
+ #### Write Code
42
+
43
+ Implement your feature or bug fix.
44
+
45
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.
46
+
47
+ Make sure that `bundle exec rake` completes without errors.
48
+
49
+ #### Write Documentation
50
+
51
+ Document any external behavior in the [README](README.md).
52
+
53
+ #### Update Changelog
54
+
55
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
56
+
57
+ #### Commit Changes
58
+
59
+ Make sure git knows your name and email address:
60
+
61
+ ```
62
+ git config --global user.name "Your Name"
63
+ git config --global user.email "contributor@example.com"
64
+ ```
65
+
66
+ Writing good commit logs is important. A commit log should describe what changed and why.
67
+
68
+ ```
69
+ git add ...
70
+ git commit
71
+ ```
72
+
73
+ #### Push
74
+
75
+ ```
76
+ git push origin my-feature-branch
77
+ ```
78
+
79
+ #### Make a Pull Request
80
+
81
+ Go to https://github.com/contributor/garner and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
82
+
83
+ #### Rebase
84
+
85
+ If you've been working on a change for a while, rebase with upstream/master.
86
+
87
+ ```
88
+ git fetch upstream
89
+ git rebase upstream/master
90
+ git push origin my-feature-branch -f
91
+ ```
92
+
93
+ #### Update CHANGELOG Again
94
+
95
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
96
+
97
+ ```
98
+ * [#123](https://github.com/artsy/garner/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
99
+ ```
100
+
101
+ Amend your previous commit and force push the changes.
102
+
103
+ ```
104
+ git commit --amend
105
+ git push origin my-feature-branch -f
106
+ ```
107
+
108
+ #### Check on Your Pull Request
109
+
110
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
111
+
112
+ #### Be Patient
113
+
114
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
115
+
116
+ #### Thank You
117
+
118
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.md CHANGED
@@ -212,6 +212,7 @@ The full list of `Garner.config` attributes is:
212
212
  * `:mongoid_identity_fields`: Identity fields considered legal for the `identity` method. Defaults to `[:_id]`.
213
213
  * `:caller_root`: Root path of application, to be stripped out of value strings generated by the `Caller` context key strategy. Defaults to `Rails.root` if in a Rails environment; otherwise to the nearest ancestor directory containing a Gemfile.
214
214
  * `:invalidate_mongoid_root`: If set to true, invalidates the `_root` document along with any embedded Mongoid document binding. Defaults to `true`.
215
+ * `:whiny_nils`: If set to true, raises an exception when a `nil` binding is specified (i.e., `garner.bind(nil)`). Defaults to `true`.
215
216
 
216
217
  Contributing
217
218
  ------------
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ require File.expand_path('../lib/garner/version', __FILE__)
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts 'Run `bundle install` to install missing gems'
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
17
+
18
+ Bundler::GemHelper.install_tasks
19
+
20
+ RSpec::Core::RakeTask.new(:spec) do |spec|
21
+ spec.pattern = FileList['spec/**/*_spec.rb']
22
+ end
23
+
24
+ require 'yard'
25
+ YARD::Rake::YardocTask.new(:doc)
26
+
27
+ task :benchmark do
28
+ require 'performance/strategy_benchmark'
29
+ StrategyBenchmark.new(
30
+ n: ENV['N'].try(&:to_i),
31
+ d: ENV['D'].try(&:to_i),
32
+ r: ENV['R'].try(&:to_i)
33
+ ).run!
34
+ end
35
+
36
+ require 'rubocop/rake_task'
37
+ RuboCop::RakeTask.new(:rubocop)
38
+
39
+ task default: [:rubocop, :spec]
@@ -0,0 +1,118 @@
1
+ Upgrading
2
+ =========
3
+
4
+ From <= 0.3.3 to >= 0.4.0
5
+ -------------------------
6
+
7
+ ### Binding Strategies
8
+
9
+ The API for declaring cache bindings has changed completely. Instead of passing a hash to `cache`, you may now call `bind` on the `garner` method. `bind` takes an explicit object as its argument. So, for example:
10
+
11
+ ```ruby
12
+ cache({ bind: [ User, current_user.id ] }) do
13
+ current_user.address
14
+ end
15
+ ```
16
+
17
+ now becomes:
18
+ ```ruby
19
+ garner.bind(current_user) do
20
+ current_user.address
21
+ end
22
+ ```
23
+
24
+ To accommodate virtual object bindings (object references by class name and ID alone), Garner 0.4.0 provides an `identify` method as part of its Mongoid mixin. So,
25
+
26
+ ```ruby
27
+ cache({ :bind => [Widget, params[:id]] }) { }
28
+ ```
29
+
30
+ now becomes:
31
+
32
+ ```ruby
33
+ garner.bind(Widget.identify(params[:id]))
34
+ ```
35
+
36
+ Please consult the following table for translations from all documented pre-0.4.0 Garner bindings:
37
+
38
+ | 0.3.3 Binding | 0.4.0 Binding |
39
+ |---------------|---------------|
40
+ | `bind: { klass: Widget, object: { id: params[:id] } }` | `bind(Widget.identify(id))` |
41
+ | `bind: { klass: Widget }` | `bind(Widget)` |
42
+ | `bind: [Widget]` | `bind(Widget)` |
43
+ | `bind: [Widget, params[:id]]` | `bind(Widget.identify(params[:id]))` |
44
+ | `bind: [User, { id: current_user.id }]` | `bind(current_user)` |
45
+ | `bind: [[Widget], [User, { id: current_user.id }]]` | `bind(Widget).bind(current_user)` |
46
+
47
+ ### Grape Integration
48
+
49
+ With Garner 0.4.0, a single Rack mixin provides all necessary integration for Garner and Grape. Change:
50
+
51
+ ```ruby
52
+ class API < Grape::API
53
+ use Garner::Middleware::Cache::Bust
54
+ helpers Garner::Mixins::Grape::Cache
55
+ end
56
+ ```
57
+
58
+ to:
59
+
60
+ ```ruby
61
+ class API < Grape::API
62
+ helpers Garner::Mixins::Rack
63
+ end
64
+ ```
65
+
66
+ ### Mongoid Integration
67
+
68
+ The API for Mongoid integration is unchanged. Please continue to include the Mongoid mixin by placing the following code in an initializer:
69
+
70
+ ```ruby
71
+ require "garner"
72
+ require "garner/mixins/mongoid"
73
+
74
+ module Mongoid
75
+ module Document
76
+ include Garner::Mixins::Mongoid::Document
77
+ end
78
+ end
79
+ ```
80
+
81
+ ### HTTP Caching
82
+
83
+ Garner no longer provides HTTP caching, beginning with 0.4.0. We recommend using `Rack::ConditionalGet` in combination with `Rack::ETag` instead. These can be easily mixed into your existing Grape app like so:
84
+
85
+ ```ruby
86
+ class API < Grape::API
87
+ use Rack::ConditionalGet
88
+ use Rack::ETag
89
+ end
90
+ ```
91
+
92
+ Moreover, `cache_or_304` is no longer implemented in Garner 0.4.0. All calls to `cache_or_304` should be replaced with `garner` blocks, just like any `cache` block. To give a specific example,
93
+
94
+ ```ruby
95
+ cache_or_304({ bind: [ User, current_user.id ] }) do
96
+ current_user.address
97
+ end
98
+ ```
99
+
100
+ should become:
101
+
102
+ ```ruby
103
+ garner.bind(current_user) do
104
+ current_user.address
105
+ end
106
+ ```
107
+
108
+ ### Context Key Strategies
109
+
110
+ You should no longer need to explicitly define key strategies. You can remove definitions like:
111
+
112
+ ```ruby
113
+ Garner::Cache::ObjectIdentity::KEY_STRATEGIES = [
114
+ # ...
115
+ ]
116
+ ```
117
+
118
+ from your initializers. If you have custom context key strategies, please refer to [request_get.rb](/artsy/garner/blob/master/lib/garner/strategies/context/key/request_get.rb) for an example of how to write new context key strategies. They can be added to `Garner.config.context_key_strategies`, or if only applicable to the Rack context, `Garner.config.rack_context_key_strategies`.