kasket 4.4.5 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9f87cf99e6a474e1fbd9cc065f70b7d3fdf8d63e
4
- data.tar.gz: b80fdd81db181a37ce17307b766b8226b1d585f0
2
+ SHA256:
3
+ metadata.gz: e5cec0e5e944a74b977fd8e8113983160e1a5075eade70a499e6b16863abfde6
4
+ data.tar.gz: d9ee5a1d6a974e998191ad656b4b962b5a7ea74e0327be3944813790bf6e7e8c
5
5
  SHA512:
6
- metadata.gz: 55d6fee7b35ff8fe213842590551a8855c52b26213f6a90a3993d2165fb39dc6abad1a95c8d1262dfe123124d7a269c771b8a153bbba102b45397062812434c0
7
- data.tar.gz: 51e4d7e84544db2ca0fb9f36525167bf863847d31c7b10962fab41f45070e3e2cceec3733a00186c00e5034927b6bb6ebf215fd94f11a230b3b5de74a606e430
6
+ metadata.gz: 9aca01c0f69b403d2476b5db05b610604899f2a38f450b0c29d8f19b60f5f2e3e67777c172690672ae83a1a4ce14e316c85175989d5dd4df826afdbf6b8e530c
7
+ data.tar.gz: 1645f52ca823c5c628d9fa5c1aba45393feffc9ac3f0c0e70e1552582bd55de79df20f8870f72deca67d8e0faae036d5fc5d1fa67b7be80dcf836d86808b7c68
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Kasket [![Build Status](https://secure.travis-ci.org/zendesk/kasket.svg)](http://travis-ci.org/zendesk/kasket)
1
+ # Kasket [![Build status](https://circleci.com/gh/zendesk/kasket.svg?style=svg)](https://circleci.com/gh/zendesk/kasket)
2
2
 
3
3
  ### Puts a cap on your queries
4
4
  A caching layer for ActiveRecord (3.x and 4.x)
@@ -34,8 +34,8 @@ This will include the required modules into ActiveRecord.
34
34
  By default, Kasket will cache each instance collection with a maximum length of 100.
35
35
  You can override this by passing the `:max_collection_size` option to the `Kasket.setup` call:
36
36
 
37
- ```
38
- Kasket.setup(:max_collection_size => 50)
37
+ ```ruby
38
+ Kasket.setup(max_collection_size: 50)
39
39
  ```
40
40
 
41
41
  #### Write-Through Caching
@@ -44,8 +44,8 @@ By default, when a model is saved, Kasket will invalidate cache entries by delet
44
44
  You can pass ':write_through => true' to the `Kasket.setup` call to get write-through cache
45
45
  semantics instead. In this mode, the model will be updated in the cache as well as the database.
46
46
 
47
- ```
48
- Kasket.setup(:write_through => true)
47
+ ```ruby
48
+ Kasket.setup(write_through: true)
49
49
  ```
50
50
 
51
51
  ## Configuring caching of your models
@@ -55,7 +55,7 @@ configuration.
55
55
 
56
56
  If you have an `Account` model, you can can do the simplest caching configuration like:
57
57
 
58
- ```
58
+ ```ruby
59
59
  Account.has_kasket
60
60
  ```
61
61
 
@@ -65,7 +65,7 @@ All other calls (say, `Account.find_by_subdomain('zendesk')`) are untouched.
65
65
 
66
66
  If you wanted to configure a caching index on the subdomain attribute of the Account model, you would simply write
67
67
 
68
- ```
68
+ ```ruby
69
69
  Account.has_kasket_on :subdomain
70
70
  ```
71
71
 
@@ -81,6 +81,7 @@ The goal of Kasket is to be as safe as possible to use, so the cache is expired
81
81
  * When you save a model instance
82
82
  * When your database schema changes
83
83
  * When you install a new version of Kasket
84
+ * After a global or per-model TTL
84
85
  * When you ask it to
85
86
 
86
87
  ### Cache expiry on instance save
@@ -96,12 +97,26 @@ If you somehow change your table schema, all cache entries for that table will a
96
97
 
97
98
  All Kasket cache keys contain the Kasket version number, so upgrading Kasket will expire all Kasket cache entries.
98
99
 
100
+ ### Cache expiry by TTL
101
+
102
+ Sometimes caches like memcache can become incoherent. One layer of mitigation for this problem is to specify the maximum length a value may stay in cache before being expired and re-calculated. You can configure an optional default TTL value at setup:
103
+
104
+ ```ruby
105
+ Kasket.setup(default_expires_in: 24.hours)
106
+ ```
107
+
108
+ You can further specify per-model TTL values:
109
+
110
+ ```ruby
111
+ Account.kasket_expires_in 5.minutes
112
+ ```
113
+
99
114
  ### Manually expiring caches
100
115
 
101
116
  If you have model methods that update the database behind the back of ActiveRecord, you need to mark these methods
102
117
  as being dirty.
103
118
 
104
- ```
119
+ ```ruby
105
120
  Account.kasket_dirty_methods :update_last_action
106
121
  ```
107
122
 
@@ -15,7 +15,11 @@ module Kasket
15
15
  autoload :SelectManagerMixin, 'kasket/select_manager_mixin'
16
16
  autoload :RelationMixin, 'kasket/relation_mixin'
17
17
 
18
- CONFIGURATION = { max_collection_size: 100, write_through: false } # rubocop:disable Style/MutableConstant
18
+ CONFIGURATION = { # rubocop:disable Style/MutableConstant
19
+ max_collection_size: 100,
20
+ write_through: false,
21
+ default_expires_in: nil
22
+ }
19
23
 
20
24
  module_function
21
25
 
@@ -23,7 +27,8 @@ module Kasket
23
27
  return if ActiveRecord::Base.respond_to?(:has_kasket)
24
28
 
25
29
  CONFIGURATION[:max_collection_size] = options[:max_collection_size] if options[:max_collection_size]
26
- CONFIGURATION[:write_through] = options[:write_through] if options[:write_through]
30
+ CONFIGURATION[:write_through] = options[:write_through] if options[:write_through]
31
+ CONFIGURATION[:default_expires_in] = options[:default_expires_in] if options[:default_expires_in]
27
32
 
28
33
  ActiveRecord::Base.extend(Kasket::ConfigurationMixin)
29
34
 
@@ -37,8 +37,8 @@ module Kasket
37
37
  else
38
38
  key = attribute_value_pairs.map do |attribute, value|
39
39
  column = columns_hash[attribute.to_s]
40
- value = nil if value.blank?
41
- "#{attribute}=#{quoted_value_for_column(value, column)}"
40
+ value = nil if value.blank? && value != false
41
+ "#{attribute}=#{kasket_quoted_value_for_column(value, column)}"
42
42
  end.join('/')
43
43
 
44
44
  if key.size > (250 - kasket_key_prefix.size) || key =~ /\s/
@@ -91,21 +91,23 @@ module Kasket
91
91
  @kasket_ttl = time
92
92
  end
93
93
 
94
- attr_reader :kasket_ttl
94
+ def kasket_ttl
95
+ @kasket_ttl ||= nil
96
+ @kasket_ttl || Kasket::CONFIGURATION[:default_expires_in]
97
+ end
95
98
 
96
99
  private
97
100
 
98
- def quoted_value_for_column(value, column)
101
+ def kasket_quoted_value_for_column(value, column)
99
102
  if column
103
+ conn = connection
100
104
  casted_value =
101
- if connection.respond_to?(:type_cast_from_column)
102
- connection.type_cast_from_column(column, value)
103
- elsif column.respond_to?(:type_cast_for_database)
104
- column.type_cast_for_database(value) # Rails 4.2
105
- else
106
- column.type_cast(value)
105
+ case ActiveRecord::VERSION::MAJOR
106
+ when 3 then column.type_cast(value)
107
+ when 4 then column.type_cast_for_database(value)
108
+ else conn.type_cast_from_column(column, value)
107
109
  end
108
- connection.quote(casted_value).downcase
110
+ conn.quote(casted_value).downcase
109
111
  else
110
112
  value.to_s
111
113
  end
@@ -16,7 +16,11 @@ module Kasket
16
16
  if ActiveRecord::VERSION::MAJOR < 5
17
17
  sql.to_kasket_query(self, args[1])
18
18
  else
19
- sql.to_kasket_query(self, args[1].map(&:value_for_database))
19
+ if ActiveRecord::VERSION::STRING < '5.2'
20
+ sql.to_kasket_query(self, args[1].map(&:value_for_database))
21
+ else
22
+ sql.to_kasket_query(self)
23
+ end
20
24
  end
21
25
  else
22
26
  kasket_parser.parse(sanitize_sql(sql))
@@ -6,7 +6,7 @@ module Kasket
6
6
  if ActiveRecord::VERSION::MAJOR < 5
7
7
  arel.to_kasket_query(klass, (binds || bind_values))
8
8
  else
9
- arel.to_kasket_query(klass, (@values[:where].binds.map(&:value_for_database) + Array(@values[:limit])))
9
+ arel.to_kasket_query(klass, (@values[:where].to_h.values + Array(@values[:limit])))
10
10
  end
11
11
  end
12
12
  rescue TypeError # unsupported object in ast
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Kasket
3
- VERSION = '4.4.5'
3
+ VERSION = '4.8.0'
4
4
  class Version
5
5
  MAJOR = Kasket::VERSION.split('.')[0]
6
6
  MINOR = Kasket::VERSION.split('.')[1]
@@ -119,11 +119,15 @@ module Kasket
119
119
  end
120
120
  end
121
121
 
122
- def visit_Arel_Nodes_BindParam(_x, *_)
122
+ def visit_Arel_Nodes_BindParam(node, *_)
123
123
  if ActiveRecord::VERSION::MAJOR < 5
124
124
  visit(@binds.shift[1])
125
125
  else
126
- visit(@binds.shift)
126
+ if ActiveRecord::VERSION::STRING < '5.2'
127
+ visit(@binds.shift)
128
+ else
129
+ visit(node.value.value) unless node.value.value.nil?
130
+ end
127
131
  end
128
132
  end
129
133
 
@@ -132,7 +136,11 @@ module Kasket
132
136
  end
133
137
 
134
138
  def visit_Arel_Nodes_Casted(node, *_)
135
- quoted(node.val) unless node.val.nil?
139
+ case node.val
140
+ when nil then nil
141
+ when String then node.val
142
+ else quoted(node.val)
143
+ end
136
144
  end
137
145
 
138
146
  def visit_TrueClass(_node)
@@ -144,7 +152,6 @@ module Kasket
144
152
  end
145
153
 
146
154
  def quoted(node)
147
- return node if node.is_a?(String)
148
155
  @model_class.connection.quote(node)
149
156
  end
150
157
 
@@ -155,6 +162,8 @@ module Kasket
155
162
 
156
163
  alias_method :visit_String, :literal
157
164
  alias_method :visit_Fixnum, :literal
165
+ alias_method :visit_Integer, :literal
166
+ alias_method :visit_Bignum, :literal
158
167
  alias_method :visit_Arel_Nodes_SqlLiteral, :literal
159
168
  end
160
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kasket
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.5
4
+ version: 4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-11 00:00:00.000000000 Z
12
+ date: 2020-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,20 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '3.2'
20
+ version: '4.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5.2'
23
+ version: '6.1'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: '3.2'
30
+ version: '4.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '6.1'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rake
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -173,15 +173,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
173
  requirements:
174
174
  - - ">="
175
175
  - !ruby/object:Gem::Version
176
- version: 2.2.0
176
+ version: 2.3.0
177
177
  required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  requirements:
179
179
  - - ">="
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubyforge_project:
184
- rubygems_version: 2.6.13
183
+ rubygems_version: 3.1.4
185
184
  signing_key:
186
185
  specification_version: 4
187
186
  summary: A write back caching layer on active record