garner 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Garner [![Build Status](https://secure.travis-ci.org/artsy/garner.png)](http://travis-ci.org/artsy/garner) [![Dependency Status](https://gemnasium.com/artsy/garner.png)](https://gemnasium.com/artsy/garner) [![Coverage Status](https://coveralls.io/repos/artsy/garner/badge.png)](https://coveralls.io/r/artsy/garner)
1
+ Garner [![Build Status](https://secure.travis-ci.org/artsy/garner.png)](http://travis-ci.org/artsy/garner) [![Dependency Status](https://gemnasium.com/artsy/garner.png)](https://gemnasium.com/artsy/garner) [![Coverage Status](https://coveralls.io/repos/artsy/garner/badge.png)](https://coveralls.io/r/artsy/garner) [![Code Climate](https://codeclimate.com/github/artsy/garner.png)](https://codeclimate.com/github/artsy/garner)
2
2
  ======
3
3
 
4
4
  Garner is a cache layer for Ruby and Rack applications, supporting model and instance binding and hierarchical invalidation. To "garner" means to gather data from various sources and to make it readily available in one place, kind of like a cache!
@@ -8,7 +8,7 @@ If you're not familiar with HTTP caching, ETags and If-Modified-Since, watch us
8
8
  Upgrading
9
9
  ---------
10
10
 
11
- The current stable release of Garner is 0.4.1, and contains many breaking changes from the previous stable release, 0.3.3. For a summary of important changes, see [UPGRADING](UPGRADING.md).
11
+ The current stable release line of Garner is 0.4.x, and contains many breaking changes from the previous 0.3.x series. For a summary of important changes, see [UPGRADING](UPGRADING.md).
12
12
 
13
13
  Usage
14
14
  -----
@@ -18,7 +18,7 @@ Usage
18
18
  Add Garner to your Gemfile with `gem "garner"` and run `bundle install`. Next, include the appropriate mixin in your app:
19
19
 
20
20
  * For plain-old Ruby apps, `include Garner::Cache::Context`.
21
- * For Rack apps, `include Garner::Mixins::Rack`. (This provides saner defaults for injecting request parameters into the cache context key. More on cache context keys later.)
21
+ * For Rack apps, first `require "garner/mixins/rack"`, then `include Garner::Mixins::Rack`. (This provides saner defaults for injecting request parameters into the cache context key. More on cache context keys later.)
22
22
 
23
23
  Now, to use Garner's cache, invoke `garner` with a logic block from within your application. The result of the block will be computed once, and then stored in the cache.
24
24
 
@@ -54,6 +54,8 @@ ORM Integrations
54
54
  To use Mongoid documents and classes for Garner bindings, use `Garner::Mixins::Mongoid::Document`. You can set it up in an initializer:
55
55
 
56
56
  ``` ruby
57
+ require "garner/mixins/mongoid"
58
+
57
59
  module Mongoid
58
60
  module Document
59
61
  include Garner::Mixins::Mongoid::Document
@@ -122,6 +124,19 @@ module ActiveRecord
122
124
  end
123
125
  ```
124
126
 
127
+ Cache Options
128
+ -------------
129
+
130
+ You can pass additional options directly to the cache implementation:
131
+
132
+ ``` ruby
133
+ get "/latest_order" do
134
+ # Expire the latest order every 15 minutes
135
+ garner.options(expires_in: 15.minutes) do
136
+ Order.latest
137
+ end
138
+ end
139
+ ```
125
140
 
126
141
  Under The Hood: Bindings
127
142
  ------------------------
@@ -38,15 +38,28 @@ module Garner
38
38
  Mongoid::Identity.from_class_and_handle(self, handle)
39
39
  end
40
40
 
41
- # Find an object by _id, or other findable field, first trying to
42
- # fetch from Garner's cache.
41
+ # Find an object by _id, or other findable field, or by multiple findable
42
+ # fields, first trying to fetch from Garner's cache.
43
43
  #
44
- # @return [Mongoid::Document]
45
- def self.garnered_find(handle)
46
- return nil unless (binding = identify(handle))
44
+ #
45
+ # @example Find by an id.
46
+ # Garner::Mixins::Mongoid::Document.garnered_find(BSON::ObjectId.new)
47
+ #
48
+ # @example Find by multiple id's.
49
+ # Garner::Mixins::Mongoid::Document.garnered_find(BSON::ObjectId.new, BSON::ObjectId.new)
50
+ #
51
+ # @example Find by multiple id's in an array.
52
+ # Garner::Mixins::Mongoid::Document.garnered_find([ BSON::ObjectId.new, BSON::ObjectId.new ])
53
+ #
54
+ # @return [ Array<Mongoid::Document>, Mongoid::Document ]
55
+ def self.garnered_find(*args)
47
56
  identity = Garner::Cache::Identity.new
48
- identity.bind(binding).key({ :source => :garnered_find }) do
49
- find(handle)
57
+ args.flatten.each do |arg|
58
+ binding = identify(arg)
59
+ identity = identity.bind(binding)
60
+ end
61
+ identity.key({ :garnered_find_args => args }) do
62
+ find(*args)
50
63
  end
51
64
  end
52
65
 
@@ -30,6 +30,7 @@ module Garner
30
30
  #
31
31
  # @return [Mongoid::Document]
32
32
  def proxy_binding
33
+ return nil unless handle
33
34
  @proxy_binding ||= klass.where(conditions).only(:_id, :_type, :updated_at).limit(1).entries.first
34
35
  end
35
36
 
@@ -50,7 +51,7 @@ module Garner
50
51
  end
51
52
 
52
53
  def self.conditions_for(klass, handle)
53
- # multiple-ID conditions
54
+ # Multiple-ID conditions
54
55
  conditions = {
55
56
  "$or" => Garner.config.mongoid_identity_fields.map { |field|
56
57
  { field => handle }
@@ -1,3 +1,3 @@
1
1
  module Garner
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-11 00:00:00.000000000 Z
13
+ date: 2013-10-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -400,7 +400,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
400
400
  version: '0'
401
401
  segments:
402
402
  - 0
403
- hash: 4248293876720409745
403
+ hash: 1633170604903825081
404
404
  required_rubygems_version: !ruby/object:Gem::Requirement
405
405
  none: false
406
406
  requirements: