readthis 1.2.0 → 1.2.1
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 +49 -10
- data/lib/readthis/cache.rb +1 -1
- data/lib/readthis/entity.rb +1 -1
- data/lib/readthis/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: 2c3b9c325211a544d3cdffbbb4356c7c392a5c04
|
4
|
+
data.tar.gz: ecd6d0982a96bcff0f9bfafff60b6d758ab5ee55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92323a5bfb41f8a29ea0b3082ff500078af9944d85fd756a1147b2cc1a7899e7fa4900c086463bfaa775608cf3d7c86137b4e54084f72ce1a2110b3f14d55c2b
|
7
|
+
data.tar.gz: f2d19489b82236baee8be73033b07f3a375585195fc251b17c5ce9f15972911e696e038b282a949a513c8afda4465706f2a581b90c99529da7255e364fe9517b
|
data/README.md
CHANGED
@@ -5,9 +5,10 @@
|
|
5
5
|
|
6
6
|
# Readthis
|
7
7
|
|
8
|
-
Readthis is a
|
9
|
-
|
10
|
-
|
8
|
+
Readthis is a Redis backed cache client for Ruby. It is a drop in replacement
|
9
|
+
for any `ActiveSupport` compliant cache and can also be used for [session
|
10
|
+
storage](#session-storage). Above all Readthis emphasizes performance,
|
11
|
+
simplicity, and explicitness.
|
11
12
|
|
12
13
|
For new projects there isn't any reason to stick with Memcached. Redis is as
|
13
14
|
fast, if not faster in many scenarios, and is far more likely to be used
|
@@ -65,24 +66,29 @@ instances have numerous benefits like: more predictable performance, avoiding
|
|
65
66
|
expires in favor of LRU, and tuning the persistence mechanism. See [Optimizing
|
66
67
|
Redis Usage for Caching][optimizing-usage] for more details.
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
At the very least you'll want to use a specific database for caching. In the
|
69
|
+
At the very least, you'll want to use a specific database for caching. In the
|
71
70
|
event the database needs to be purged you can do so with a single `clear`
|
72
71
|
command, rather than finding all keys in a namespace and deleting them.
|
73
72
|
Appending a number between 0 and 15 will specify the redis database, which
|
74
|
-
defaults to 0
|
73
|
+
defaults to `0`. For example, using database `2`:
|
75
74
|
|
76
75
|
```bash
|
77
76
|
REDIS_URL=redis://localhost:6379/2
|
78
77
|
```
|
79
78
|
|
79
|
+
[optimizing-usage]: http://sorentwo.com/2015/07/27/optimizing-redis-usage-for-caching.html
|
80
|
+
|
80
81
|
### Expiration
|
81
82
|
|
82
83
|
Be sure to use an integer value when setting expiration time. The default
|
83
84
|
representation of `ActiveSupport::Duration` values won't work when setting
|
84
85
|
expiration time, which will cause all keys to have `-1` as the TTL. Expiration
|
85
|
-
values are always cast as an integer on write.
|
86
|
+
values are always cast as an integer on write. For example:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
Readthis::Cache.new(expires_in: 1.week) # don't do this
|
90
|
+
Readthis::Cache.new(expires_in: 1.week.to_i) # do this
|
91
|
+
```
|
86
92
|
|
87
93
|
### Compression
|
88
94
|
|
@@ -132,7 +138,7 @@ Readthis.serializers.freeze!
|
|
132
138
|
Readthis::Cache.new(marshal: Oj)
|
133
139
|
```
|
134
140
|
|
135
|
-
Be aware that the order in which you add serializers matters
|
141
|
+
Be aware that the *order in which you add serializers matters*. Serializers are
|
136
142
|
sticky and a flag is stored with each cached value. If you subsequently go to
|
137
143
|
deserialize values and haven't configured the same serializers in the same order
|
138
144
|
your application will raise errors.
|
@@ -140,7 +146,7 @@ your application will raise errors.
|
|
140
146
|
## Fault Tolerance
|
141
147
|
|
142
148
|
In some situations it is desirable to keep serving requests from disk or the
|
143
|
-
database if Redis crashes. This can be achieved
|
149
|
+
database if Redis crashes. This can be achieved with connection fault tolerance
|
144
150
|
by enabling it at the top level:
|
145
151
|
|
146
152
|
```ruby
|
@@ -150,6 +156,16 @@ Readthis.fault_tolerant = true
|
|
150
156
|
The default value is `false`, because while it may work for `fetch` operations,
|
151
157
|
it isn't compatible with other state-based commands like `increment`.
|
152
158
|
|
159
|
+
## Running Arbitrary Redis Commands
|
160
|
+
|
161
|
+
Readthis provides access to the underlying Redis connection pool, allowing you
|
162
|
+
to run arbitrary commands directly through the cache instance. For example, if
|
163
|
+
you wanted to expire a key manually using an instance of `Rails.cache`:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
Rails.cache.pool.with { |client| client.expire('foo-key', 60) }
|
167
|
+
```
|
168
|
+
|
153
169
|
## Differences From ActiveSupport::Cache
|
154
170
|
|
155
171
|
Readthis supports all of standard cache methods except for the following:
|
@@ -157,11 +173,34 @@ Readthis supports all of standard cache methods except for the following:
|
|
157
173
|
* `cleanup` - Redis does this with TTL or LRU already.
|
158
174
|
* `delete_matched` - You really don't want to perform key matching operations in
|
159
175
|
Redis. They are linear time and only support basic globbing.
|
176
|
+
* `mute` and `silence!` - You can subscribe to the events `/cache*+active_support/` with `ActiveSupport::Notifications` to [log cache calls manually][notifications].
|
177
|
+
|
178
|
+
[notifications]: https://github.com/sorentwo/readthis/issues/22#issuecomment-142595938
|
160
179
|
|
161
180
|
Like other `ActiveSupport::Cache` implementations it is possible to cache `nil`
|
162
181
|
as a value. However, the fetch methods treat `nil` values as a cache miss and
|
163
182
|
re-generate/re-cache the value. Caching `nil` isn't recommended.
|
164
183
|
|
184
|
+
## Session Storage
|
185
|
+
|
186
|
+
By using [ActionDispatch::Session::CacheStore][cache-store] it's possible to
|
187
|
+
reuse `:readthis_store` or specify a new Readthis cache store for storing
|
188
|
+
sessions.
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
Rails.application.config.session_store :cache_store
|
192
|
+
```
|
193
|
+
|
194
|
+
To specify a separate Readthis instance you can use the `:cache` option:
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
Rails.application.config.session_store :cache_store,
|
198
|
+
cache: Readthis::Cache.new,
|
199
|
+
expire_after: 2.weeks.to_i
|
200
|
+
```
|
201
|
+
|
202
|
+
[cache-store]: http://api.rubyonrails.org/classes/ActionDispatch/Session/CacheStore.html
|
203
|
+
|
165
204
|
## Contributing
|
166
205
|
|
167
206
|
1. Fork it
|
data/lib/readthis/cache.rb
CHANGED
@@ -212,7 +212,7 @@ module Readthis
|
|
212
212
|
return {} if keys.empty?
|
213
213
|
|
214
214
|
invoke(:read_multi, keys) do |store|
|
215
|
-
values = store.mget(mapping).map { |value| entity.load(value) }
|
215
|
+
values = store.mget(*mapping).map { |value| entity.load(value) }
|
216
216
|
|
217
217
|
keys.zip(values).to_h
|
218
218
|
end
|
data/lib/readthis/entity.rb
CHANGED
data/lib/readthis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readthis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.5.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Pooled active support compliant caching with redis
|