kasket 4.5.1 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -7
- data/lib/kasket.rb +7 -2
- data/lib/kasket/configuration_mixin.rb +4 -1
- data/lib/kasket/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a81925a9561dbeb413c751be411178db3ca412f1
|
4
|
+
data.tar.gz: 32e1620ff89925cc429d4c9f8e8bfdc95e34208e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c57079f331c15b58809288a45c123ff8e044763c81f0e170a9706305fcb0ea6d7f0fd336566815bf99e843d4193e9dbc1b6d96ad4543317e4fb6d79a89eece28
|
7
|
+
data.tar.gz: d8a5b52ce07b72b361727649697a8a1187c55fe790dbbf82b7b358897cf942fe64456ce89959a9849f9f941f99b854e2a2b41931c178890ddf4d1bae9c06e8aa
|
data/README.md
CHANGED
@@ -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(:
|
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(:
|
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
|
|
data/lib/kasket.rb
CHANGED
@@ -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 = {
|
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]
|
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
|
|
data/lib/kasket/version.rb
CHANGED
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
|
+
version: 4.6.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-
|
12
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.5.
|
184
|
+
rubygems_version: 2.5.2
|
185
185
|
signing_key:
|
186
186
|
specification_version: 4
|
187
187
|
summary: A write back caching layer on active record
|