readthis 0.7.0 → 0.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
2
  SHA1:
3
- metadata.gz: beeb6a1ebaa7b28ece28bbc82b71a85bd78db186
4
- data.tar.gz: 5c1af1a823131e8320c862b4774e285c08ad8525
3
+ metadata.gz: a07bacb5dfde0174d8c1bbb84f67f4a4fa110a78
4
+ data.tar.gz: e33d843547462b265a33333106f68b634e1d22fd
5
5
  SHA512:
6
- metadata.gz: f418008520264991ec238afda668dadea6b42724df8b638b858dada82e0bc5263aea0fa3fd6ffc48839da51fd3153fdd436d348de60fa996cfdc7c57750b2c76
7
- data.tar.gz: db0e5445ea22524934d4257347ad28584b8fb03c7b2acfa6c543ce655d76d7f96b5af19d2efada2ed6be22a5afad34dcdf10c5132a466bad2b3b5ee00d68be01
6
+ metadata.gz: 4e50977ab026bfd2df4824b9da0d2ed043005ecd7dd6f747ba431516f6f09d888f51fa5f56619871f462b602e4d4c882e44ab39c80a98d9d0fed48943a97eae6
7
+ data.tar.gz: 800a1d90af2fb5a9edd694ae6cea7b319f6e47026394d8dd72fa407c0228766124786f7e22260637baac6a7f36ac4fb8249403c955f6b583334d4f47d823e682
data/.travis.yml CHANGED
@@ -1,12 +1,14 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.0.0
4
5
  - 2.1.0
5
6
  - 2.2.2
6
7
  - ruby-head
7
8
  - rbx-2
8
9
  matrix:
9
10
  allow_failures:
11
+ - rvm: 2.0.0
10
12
  - rvm: ruby-head
11
13
  - rvm: rbx-2
12
14
  services:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v0.8.0 2015-08-26
2
+
3
+ - Breaking: The initializer now takes a single options argument instead of a
4
+ `url` and `options` separately. This allows the underlying redis client to
5
+ accept any options, rather than just the driver. For example, it's now
6
+ possible to use Readthis with sentinel directly through the configuration.
7
+ - Changed: The `hiredis` driver is *no longer the default*. In order to use the
8
+ vastly faster `hiredis` driver you need to pass it in during construction.
9
+ See [readthis#9][issue-9] for more discussion.
10
+
11
+ [issue-9]: https://github.com/sorentwo/readthis/issues/9
12
+
1
13
  ## v0.7.0 2015-08-11
2
14
 
3
15
  - Changed: Entity initialization uses an options hash rather than keyword
data/README.md CHANGED
@@ -25,6 +25,7 @@ Add this line to your application's Gemfile:
25
25
 
26
26
  ```ruby
27
27
  gem 'readthis'
28
+ gem 'hiredis' # Highly recommended
28
29
  ```
29
30
 
30
31
  ## Usage
@@ -33,10 +34,10 @@ Use it the same way as any other [ActiveSupport::Cache::Store][store]. Within a
33
34
  Rails environment config:
34
35
 
35
36
  ```ruby
36
- config.cache_store = :readthis_store, ENV.fetch('REDIS_URL'), {
37
+ config.cache_store = :readthis_store,
37
38
  expires_in: 2.weeks.to_i,
38
- namespace: 'cache'
39
- }
39
+ namespace: 'cache',
40
+ redis: { url: ENV.fetch('REDIS_URL'), driver: :hiredis }
40
41
  ```
41
42
 
42
43
  Otherwise you can use it anywhere, without any reliance on `ActiveSupport`:
@@ -44,7 +45,10 @@ Otherwise you can use it anywhere, without any reliance on `ActiveSupport`:
44
45
  ```ruby
45
46
  require 'readthis'
46
47
 
47
- cache = Readthis::Cache.new(ENV.fetch('REDIS_URL'), expires_in: 2.weeks.to_i)
48
+ cache = Readthis::Cache.new(
49
+ expires_in: 2.weeks.to_i,
50
+ redis: { url: ENV.fetch('REDIS_URL') }
51
+ )
48
52
  ```
49
53
 
50
54
  [store]: http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
@@ -85,10 +89,9 @@ means it is safe to enable or change compression with an existing cache. There
85
89
  will be a decoding performance penalty in this case, but it should be minor.
86
90
 
87
91
  ```ruby
88
- config.cache_store = :readthis_store, ENV.fetch('REDIS_URL'), {
92
+ config.cache_store = :readthis_store,
89
93
  compress: true,
90
94
  compression_threshold: 2.kilobytes
91
- }
92
95
  ```
93
96
 
94
97
  ### Marshalling
@@ -100,22 +103,22 @@ may be desirable to use a faster but less flexible marshaller.
100
103
  Use Oj for JSON marshalling, extremely fast, but supports limited types:
101
104
 
102
105
  ```ruby
103
- Readthis::Cache.new(url, marshal: Oj)
106
+ Readthis::Cache.new(marshal: Oj)
104
107
  ```
105
108
 
106
109
  If all cached data can safely be represented as a string then use the
107
110
  pass-through marshaller:
108
111
 
109
112
  ```ruby
110
- Readthis::Cache.new(url, marshal: Readthis::Passthrough)
113
+ Readthis::Cache.new(marshal: Readthis::Passthrough)
111
114
  ```
112
115
 
113
- ## Differences
116
+ ## Differences From ActiveSupport::Cache
114
117
 
115
118
  Readthis supports all of standard cache methods except for the following:
116
119
 
117
120
  * `cleanup` - Redis does this with TTL or LRU already.
118
- * `delete_matched` - you really don't want to perform key matching operations
121
+ * `delete_matched` - You really don't want to perform key matching operations
119
122
  in Redis. They are linear time and only support basic globbing.
120
123
 
121
124
  ## Contributing
@@ -16,7 +16,6 @@ dalli = ActiveSupport::Cache::DalliStore.new(
16
16
  )
17
17
 
18
18
  readthis = Readthis::Cache.new(
19
- 'redis://localhost:6379/11',
20
19
  pool_size: 5,
21
20
  compressed: true,
22
21
  compression_threshold: 128
data/benchmarks/driver.rb CHANGED
@@ -5,9 +5,8 @@ Bundler.setup
5
5
  require 'benchmark/ips'
6
6
  require 'readthis'
7
7
 
8
- REDIS_URL = 'redis://localhost:6379/11'
9
- native = Readthis::Cache.new(REDIS_URL, driver: :ruby, expires_in: 60)
10
- hiredis = Readthis::Cache.new(REDIS_URL, driver: :hiredis, expires_in: 60)
8
+ native = Readthis::Cache.new(redis: { driver: :ruby }, expires_in: 60)
9
+ hiredis = Readthis::Cache.new(redis: { driver: :hiredis }, expires_in: 60)
11
10
 
12
11
  ('a'..'z').each { |key| native.write(key, key * 1024) }
13
12
 
@@ -9,14 +9,13 @@ require 'msgpack'
9
9
  require 'readthis'
10
10
  require 'readthis/passthrough'
11
11
 
12
- REDIS_URL = 'redis://localhost:6379/11'
13
- OPTIONS = { compressed: false }
14
-
15
- readthis_pass = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: Readthis::Passthrough))
16
- readthis_oj = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: Oj))
17
- readthis_msgpack = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: MessagePack))
18
- readthis_json = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: JSON))
19
- readthis_ruby = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: Marshal))
12
+ OPTIONS = { compressed: false }
13
+
14
+ readthis_pass = Readthis::Cache.new(OPTIONS.merge(marshal: Readthis::Passthrough))
15
+ readthis_oj = Readthis::Cache.new(OPTIONS.merge(marshal: Oj))
16
+ readthis_msgpack = Readthis::Cache.new(OPTIONS.merge(marshal: MessagePack))
17
+ readthis_json = Readthis::Cache.new(OPTIONS.merge(marshal: JSON))
18
+ readthis_ruby = Readthis::Cache.new(OPTIONS.merge(marshal: Marshal))
20
19
 
21
20
  HASH = ('a'..'z').each_with_object({}) { |key, memo| memo[key] = key }
22
21
 
data/benchmarks/multi.rb CHANGED
@@ -9,11 +9,10 @@ require 'active_support/cache/memory_store'
9
9
  require 'active_support/cache/dalli_store'
10
10
  require 'readthis'
11
11
 
12
- REDIS_URL = 'redis://localhost:6379/11'
13
- memory = ActiveSupport::Cache::MemoryStore.new(expires_in: 60, namespace: 'mm')
14
- dalli = ActiveSupport::Cache::DalliStore.new('localhost', namespace: 'da', pool_size: 5, expires_in: 60)
15
- redisas = ActiveSupport::Cache::RedisStore.new(REDIS_URL + '/ra', expires_in: 60)
16
- readthis = Readthis::Cache.new(REDIS_URL, namespace: 'rd', expires_in: 60)
12
+ memory = ActiveSupport::Cache::MemoryStore.new(expires_in: 60, namespace: 'mm')
13
+ dalli = ActiveSupport::Cache::DalliStore.new('localhost', namespace: 'da', pool_size: 5, expires_in: 60)
14
+ redisas = ActiveSupport::Cache::RedisStore.new('redis://localhost:6379/11/ra', expires_in: 60)
15
+ readthis = Readthis::Cache.new(namespace: 'rd', expires_in: 60)
17
16
 
18
17
  ('a'..'z').each do |key|
19
18
  value = key * 1024
@@ -14,33 +14,31 @@ module Readthis
14
14
  # ActiveSupport::Notifications available, but needs to work even when it
15
15
  # isn't.
16
16
  def self.notifications
17
- if Object.const_defined?('ActiveSupport::Notifications')
17
+ if defined?(ActiveSupport::Notifications)
18
18
  ActiveSupport::Notifications
19
19
  else
20
20
  Readthis::Notifications
21
21
  end
22
22
  end
23
23
 
24
- # Creates a new Readthis::Cache object with the given redis URL. The URL
25
- # is parsed by the redis client directly.
24
+ # Creates a new Readthis::Cache object with the given options.
26
25
  #
27
- # @param [String] A redis compliant url with necessary connection details
26
+ # @option [Hash] :redis Options that will be passed to the underlying redis connection
28
27
  # @option [Boolean] :compress (false) Enable or disable automatic compression
29
- # @option [Number] :compression_threshold (8k) The size a string must be for compression
30
- # @option [Number] :expires_in The number of seconds until an entry expires
31
- # @option [Module] :marshal (Marshal) Any module that responds to `dump` and `load`
32
- # @option [String] :namespace Prefix used to namespace entries
33
- # @option [Symbol] :driver (:hiredis) Specify a driver to be used for Redis connections
34
- # @option [Number] :pool_size (5) The number of threads in the pool
35
- # @option [Number] :pool_timeout (5) How long before a thread times out
28
+ # @option [Number] :compression_threshold (8k) The size a string must be for compression
29
+ # @option [Number] :expires_in The number of seconds until an entry expires
30
+ # @option [Module] :marshal (Marshal) Any module that responds to `dump` and `load`
31
+ # @option [String] :namespace Prefix used to namespace entries
32
+ # @option [Number] :pool_size (5) The number of threads in the pool
33
+ # @option [Number] :pool_timeout (5) How long before a thread times out
36
34
  #
37
35
  # @example Create a new cache instance
38
- # Readthis::Cache.new('redis://localhost:6379/0', namespace: 'cache')
36
+ # Readthis::Cache.new(namespace: 'cache', redis: { url: 'redis://localhost:6379/0' })
39
37
  #
40
38
  # @example Create a compressed cache instance
41
- # Readthis::Cache.new('redis://localhost:6379/0', compress: true, compression_threshold: 2048)
39
+ # Readthis::Cache.new(compress: true, compression_threshold: 2048)
42
40
  #
43
- def initialize(url, options = {})
41
+ def initialize(options = {})
44
42
  @expires_in = options.fetch(:expires_in, nil)
45
43
  @namespace = options.fetch(:namespace, nil)
46
44
 
@@ -51,7 +49,7 @@ module Readthis
51
49
  )
52
50
 
53
51
  @pool = ConnectionPool.new(pool_options(options)) do
54
- Redis.new(url: url, driver: options.fetch(:driver, :hiredis))
52
+ Redis.new(options.fetch(:redis, {}))
55
53
  end
56
54
  end
57
55
 
@@ -1,3 +1,3 @@
1
1
  module Readthis
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -1,8 +1,7 @@
1
1
  require 'readthis/cache'
2
2
 
3
3
  RSpec.describe Readthis::Cache do
4
- let(:url) { 'redis://localhost:6379/11' }
5
- let(:cache) { Readthis::Cache.new(url) }
4
+ let(:cache) { Readthis::Cache.new }
6
5
 
7
6
  after do
8
7
  cache.clear
@@ -10,34 +9,26 @@ RSpec.describe Readthis::Cache do
10
9
 
11
10
  describe '#initialize' do
12
11
  it 'accepts and persists a namespace' do
13
- cache = Readthis::Cache.new(url, namespace: 'kash')
12
+ cache = Readthis::Cache.new(namespace: 'kash')
14
13
 
15
14
  expect(cache.namespace).to eq('kash')
16
15
  end
17
16
 
18
17
  it 'accepts and persists an expiration' do
19
- cache = Readthis::Cache.new(url, expires_in: 10)
18
+ cache = Readthis::Cache.new(expires_in: 10)
20
19
 
21
20
  expect(cache.expires_in).to eq(10)
22
21
  end
23
22
  end
24
23
 
25
24
  describe '#pool' do
26
- it 'creates a new redis connection with hiredis' do
27
- cache = Readthis::Cache.new(url)
25
+ it 'uses the passed redis configuration' do
26
+ cache = Readthis::Cache.new(redis: { driver: :hiredis })
28
27
 
29
28
  cache.pool.with do |client|
30
29
  expect(client.client.driver).to be(Redis::Connection::Hiredis)
31
30
  end
32
31
  end
33
-
34
- it 'creates a new redis connection with a custom driver' do
35
- cache = Readthis::Cache.new(url, driver: :ruby)
36
-
37
- cache.pool.with do |client|
38
- expect(client.client.driver).to be(Redis::Connection::Ruby)
39
- end
40
- end
41
32
  end
42
33
 
43
34
  describe '#write' do
@@ -87,8 +78,8 @@ RSpec.describe Readthis::Cache do
87
78
 
88
79
  describe 'compression' do
89
80
  it 'round trips entries when compression is enabled' do
90
- com_cache = Readthis::Cache.new(url, compress: true, compression_threshold: 8)
91
- raw_cache = Readthis::Cache.new(url)
81
+ com_cache = Readthis::Cache.new(compress: true, compression_threshold: 8)
82
+ raw_cache = Readthis::Cache.new
92
83
  value = 'enough text that it should be compressed'
93
84
 
94
85
  com_cache.write('compressed', value)
@@ -98,7 +89,7 @@ RSpec.describe Readthis::Cache do
98
89
  end
99
90
 
100
91
  it 'round trips bulk entries when compression is enabled' do
101
- cache = Readthis::Cache.new(url, compress: true, compression_threshold: 8)
92
+ cache = Readthis::Cache.new(compress: true, compression_threshold: 8)
102
93
  value = 'also enough text to compress'
103
94
 
104
95
  cache.write('comp-a', value)
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: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Selbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis